389 Commits

Author SHA1 Message Date
ccee5f9f56 FIX: more details 2025-06-27 16:58:15 -04:00
9677f11aef FIX: seguir cuando existe error. 2025-06-27 16:56:24 -04:00
c21de2848d FIX: saltarse lineas comentadas 2025-06-27 16:51:16 -04:00
348bb18654 LoggerEnabled Fix 2025-06-25 18:14:43 -04:00
a2a9f4bbb4 LoggerEnabled Fix 2025-06-25 18:11:28 -04:00
ab7328b40b FastCGI 2025-06-25 18:07:08 -04:00
7f97862324 Revisiones 2025-06-25 12:41:28 -04:00
9edf0d9120 Revisiones 2025-06-25 12:22:01 -04:00
ca1ed3f870 Pruebas de integracion con seeds 2025-06-24 21:55:02 -04:00
360537c638 Prueba de integracion para service worker 2025-06-24 14:24:47 -04:00
a6e6b8acc0 Prueba de integracion para service worker 2025-06-24 12:56:03 -04:00
a4e2b4fc7a Seed TipoEstadoPago 2025-06-24 12:55:46 -04:00
479047cd6a Dependencias para testeo 2025-06-24 12:55:02 -04:00
29d9ea8e4a Correr seeds y botar tablas al final 2025-06-24 12:54:48 -04:00
a7cd661938 Registro de worker 2025-06-24 12:54:32 -04:00
7bdcc7168a Container separado a archivo a parte para poder cargarlo en otros lados 2025-06-24 12:54:19 -04:00
d2dff57531 FIX: id de migracion 2025-06-24 12:53:56 -04:00
39198bbe7c get Uf asincronico 2025-06-24 11:20:53 -04:00
200510d60a Prueba Service Worker 2025-06-24 11:20:21 -04:00
ecc67a43c8 Service Worker, corre metodos de servicios asincronicamente, requiere parametros escalares y no retornar mas que bool o void 2025-06-24 11:19:58 -04:00
64791d1fc5 Alias enqueue 2025-06-24 11:16:29 -04:00
4053854410 Prueba UF 2025-06-24 11:16:19 -04:00
a687743762 FIX: No buscar UF para fechas mayores a hoy o día nueve del mes 2025-06-24 11:04:33 -04:00
38fb6f3bcc Pausa a external 2025-06-19 16:47:24 -04:00
1e6bac61b5 FIX: Limpiar archivos 2025-06-19 16:47:06 -04:00
a611ae247d FIX: prorrateo ingresado en valor % 2025-06-12 11:28:04 -04:00
c02c6eb15c FIX: Add custom HttpException 2025-06-10 19:36:56 -04:00
b7e0217cf3 FIX: remove ext-http 2025-06-10 19:35:17 -04:00
2fd1a44984 FIX: install ext-http with external script 2025-06-10 19:04:32 -04:00
fe912db62b Add ext-http 2025-06-10 18:20:05 -04:00
da90160a2a Add ext-http 2025-06-10 18:02:05 -04:00
64047ef577 TOKU: FIX: exceptions 2025-06-10 17:48:36 -04:00
feef90afd6 TOKU: payments loop through pages 2025-06-10 17:46:16 -04:00
32e1e49a97 FIX: cuerpo para borrar payments 2025-06-10 17:34:04 -04:00
11c64cb10f FIX: url para borrar 2025-06-10 17:29:39 -04:00
823f97ce5f FIX: log levels 2025-06-10 17:24:38 -04:00
4ae72199fc Better external logging 2025-06-10 17:00:20 -04:00
d841b1aeed FIX: url de payments en Toku 2025-06-10 16:57:34 -04:00
666cac1958 FIX: url de payments en Toku 2025-06-10 16:54:46 -04:00
71c189e236 FIX: circular dependency 2025-06-10 16:49:34 -04:00
5b6a1c42e3 Toku: reorden 2025-06-10 16:28:46 -04:00
81bce6fe7f Cleanup 2025-06-10 16:28:13 -04:00
e1072ea252 Toku: Reset payments 2025-06-10 16:26:33 -04:00
21473fe52c Valor cuota en CLP 2025-06-10 15:27:09 -04:00
7d589e0e87 Valor cuota en CLF 2025-06-10 15:24:51 -04:00
c48a0d2381 Valor cuota en CLP 2025-06-10 15:14:25 -04:00
abb1ce7299 Mas logging 2025-06-09 12:44:42 -04:00
f1ed9668fc email -> mail 2025-06-06 18:25:12 -04:00
f9ae809fc4 Data too large 2025-06-06 18:10:59 -04:00
06e5292af1 Log add response 2025-06-06 18:10:06 -04:00
47ba664142 Log customer params 2025-06-06 18:04:57 -04:00
d10ee33215 better format for mysql 2025-06-06 17:55:58 -04:00
5134630525 Correct Exceptions 2025-06-06 17:37:42 -04:00
13b246b998 Merge remote-tracking branch 'origin/feature/cierres' into feature/cierres 2025-06-06 17:11:33 -04:00
d601d7d719 Mas logs y middlewares en Guzzle 2025-06-06 17:11:22 -04:00
dc0ae2746b FIX: Correct HMAC validation 2025-06-03 23:07:47 -04:00
eb402b1b71 FIX: notice logs 2025-06-03 23:07:08 -04:00
c5188a1feb HMAC not static 2025-06-03 23:04:57 -04:00
1c3052219c Debug 2025-06-03 22:59:49 -04:00
9e8a388653 Debug 2025-06-03 22:59:03 -04:00
cbee830f7a Debug 2025-06-03 22:55:35 -04:00
d5b8c7f877 FIX: JSON_SEARCH 2025-06-03 22:51:26 -04:00
b668844fea Debug 2025-06-03 22:29:13 -04:00
f2169c9536 FIX: fetch all values in column 2025-06-03 22:27:15 -04:00
48bcb33bad FIX: event_types -> events 2025-06-03 22:24:09 -04:00
92ae0b4ac2 FIX: Missing connection 2025-06-03 22:22:33 -04:00
44540d0dc3 Validated external query log 2025-06-03 22:19:11 -04:00
d9a2f63691 Use webhook secrets to validate 2025-06-03 22:11:57 -04:00
b10accf602 Store webhooks 2025-06-03 22:01:03 -04:00
981858f251 HMAC implementation for signature validation 2025-06-03 21:53:49 -04:00
8c0bd450ef FIX: delete url 2025-06-03 21:26:10 -04:00
8996765cb4 FIX: maxLogLevel 2025-06-03 21:16:44 -04:00
ec2451cb69 FIX: maxLogLevel 2025-06-03 21:12:43 -04:00
37d30d2aec Cleanup logs 2025-06-03 21:09:13 -04:00
afb6e2526f FIX: Timezone cli 2025-06-03 20:14:15 -04:00
a9b6f2a87b FIX: Error code for missing TOKU_ENV 2025-06-03 19:58:36 -04:00
9aeb6906f6 Debug 2025-06-03 19:43:46 -04:00
879d365baf Not needed 2025-06-03 19:42:23 -04:00
1d03b262ae Debug 2025-06-03 19:35:36 -04:00
2c175c8171 Detailed login errors 2025-06-03 19:20:55 -04:00
a750bdbfaa Detailed login errors 2025-06-03 19:20:44 -04:00
7f6d0232c0 Cleanup files 2025-06-03 19:20:09 -04:00
37cff67a1c Log reseteando 2025-06-03 17:06:39 -04:00
bc3d739af9 Cleanup 2025-06-03 16:52:01 -04:00
46efbb57c1 Log body de reset 2025-06-03 16:25:07 -04:00
d71333b334 Queue cada 2 minutos 2025-06-03 16:13:04 -04:00
688b500f1e Parametros correctos 2025-06-03 16:06:14 -04:00
d4b1a66a9e FIX: ventas_ids vacios 2025-06-03 16:02:04 -04:00
e796d91d95 Si token no existe, no se puede borrar 2025-06-03 16:01:48 -04:00
2a442417ce FIX: Loop frequency 2025-06-03 13:01:40 -04:00
3c161ed4e9 Loop frequency 2025-06-03 12:58:57 -04:00
3c8822e531 FIX: Log job requests 2025-06-03 12:46:47 -04:00
b3b91d3f8f Log job requests 2025-06-03 12:45:36 -04:00
6e34a76a3f FIX: Request log processor no funciona 2025-06-03 12:34:08 -04:00
ed29dfb984 Request Log Processor 2025-06-03 12:17:52 -04:00
7f37dc76e3 Log forbidden 2025-06-03 12:06:35 -04:00
a62293e509 Mejora en separacion 2025-06-03 12:06:02 -04:00
fbfc2cb8ae Cambios de usos de env vars 2025-06-03 12:04:53 -04:00
02665ac6bd Extras ya enviados por processor 2025-06-03 11:52:31 -04:00
300d966f3f Separation of logs in cli 2025-06-03 11:49:03 -04:00
27031035ed Filtro en server params faltante 2025-06-03 11:45:36 -04:00
18fc9a76fd Filtro en server params 2025-06-03 11:37:14 -04:00
cb6fa73a21 FIX: Recargar proyectos si no se encuentra proyecto_id, si aun no existe retornar 0 2025-06-03 10:35:07 -04:00
8796762cfe Mas datos en el registro de accessos 2025-06-03 10:24:54 -04:00
99c9952c93 Mas datos en el registro de logins. 2025-06-03 10:22:52 -04:00
9895fd6a70 FIX: Mas registro de login desde cli 2025-06-02 18:45:11 -04:00
c1149d89be FIX: Cleanup after create, but before initialized query. 2025-06-02 18:03:43 -04:00
7d8e2249de FIX: Detalle en logging. 2025-06-02 17:58:24 -04:00
a54586e870 FIX: valor cuota cuando UF no existe. 2025-05-30 17:10:59 -04:00
734f258382 Validar con headers 2025-05-30 14:18:48 -04:00
f728ed0b55 FIX: Log de envio 2025-05-30 12:48:12 -04:00
6144accb8e FIX: Toku envía complejo el header 2025-05-29 19:56:43 -04:00
f399eb8d47 Validate with service 2025-05-29 19:43:06 -04:00
b4159d1417 Log external tries 2025-05-29 19:24:35 -04:00
2a792a947d More granular control of external validation configuration 2025-05-29 19:22:55 -04:00
25710d616a Registro de success entrantes 2025-05-29 19:15:17 -04:00
3197802264 Cleanup 2025-05-29 19:10:09 -04:00
6c53127c2f Body json 2025-05-29 19:06:54 -04:00
b7391a77d3 DEBUG: body 2025-05-29 17:44:30 -04:00
5b499aee75 Content-type 2025-05-29 17:43:14 -04:00
4505531c5f Output body 2025-05-29 17:42:21 -04:00
3f8adc753c Add body to Enqueue command 2025-05-29 17:40:45 -04:00
ace205798f FIX: Manejo de Errores en Ventas 2025-05-29 16:02:13 -04:00
6e0e1fc75e Parametros faltantes 2025-05-27 19:30:08 -04:00
026474c63c Enqueue ventas para enviar a Toku 2025-05-27 19:24:23 -04:00
f32204df97 FIX: Remove toku concept in database 2025-05-27 18:35:06 -04:00
2852816eae FIX: Parametros extra para Toku 2025-05-27 18:27:37 -04:00
892cdf324f Comando para resetear Toku 2025-05-27 18:17:56 -04:00
a9a10e012d Uso de external Logger para los servicios External 2025-05-27 16:28:34 -04:00
b7089f7a1c Timezone por DI 2025-05-27 16:19:47 -04:00
aed26cfcd8 FIX: Estado cuota abono 2025-05-23 12:15:51 -04:00
896dded6eb Apellido materno en blanco 2025-05-23 12:12:34 -04:00
3b03c4b64b Logging 2025-05-19 16:06:44 -04:00
f34ed03b84 Logging 2025-05-19 14:02:55 -04:00
ce75ec1548 External logs
FIX: Ofuscator
2025-05-19 13:55:59 -04:00
312baa34f6 Access Logs 2025-05-19 13:14:13 -04:00
b7c5e4ebc3 Opcion de enviar update a los servicios externos 2025-05-16 19:14:20 -04:00
105179b4ed Fixes de telefono y apellido de persona 2025-05-16 16:35:17 -04:00
16cd29635d Zona horaria en cli 2025-05-16 14:47:31 -04:00
2bdb2a0ed0 Uso de zona horaria en output de comandos 2025-05-16 14:44:48 -04:00
8ce7d2570d FIX: Check if invoice exists before sending, if exists then save
Send correct UF amount if date in future
2025-05-16 14:36:20 -04:00
8ba54fd3ad Queue command with direct redis access so it's faster 2025-05-16 13:56:32 -04:00
f47f86dd2b BaseLoop different logger 2025-05-16 12:54:52 -04:00
8ca68bf7e8 Crontab para revisar servicios externos 1 vez al dia 2025-05-15 19:33:53 -04:00
8965354528 Cambio en queue para que no quede pegado esperando respuesta en cli.
Chequeo de servicios externos para agregar elementos pendientes.
2025-05-15 19:32:25 -04:00
8d32aecd09 Zona horaria en logs 2025-05-15 16:07:29 -04:00
c8f79e076e Envio de datos editados de Propietario 2025-05-15 16:05:55 -04:00
9e0d604d79 Respuesta 200 a webhook de Toku 2025-05-15 16:05:03 -04:00
331d004040 Eliminar script::type 2025-05-15 16:04:35 -04:00
03317b3aa5 Agregar datos propietario 2025-05-15 15:23:34 -04:00
e33edc4d7b FIX: proyectos minuto 0 de cada hora, en vez de cada minuto de esa hora 2025-05-15 12:08:33 -04:00
bb459a2ff5 FIX: proxy no identificado por web 2025-05-15 11:47:28 -04:00
5e2d2e861f Logs no pasan desbordan de nivel 2025-05-15 10:53:59 -04:00
e9b2fe9963 FIX: monto enviado en UF 2025-05-15 10:12:34 -04:00
2f481ef8a9 FIX: mapeo de datos al actualizar pago 2025-05-15 10:06:35 -04:00
386fe452af Catch error 2025-05-15 10:06:00 -04:00
91ad1e39f8 Endpoint para la prueba 2025-05-14 12:41:59 -04:00
a3a5b58cfb Correctos parametros 2025-05-13 20:19:03 -04:00
1d77d65af2 Ventas con cuotas pendientes 2025-05-13 20:18:51 -04:00
0f0c81e283 Uso de request en queue 2025-05-13 20:18:40 -04:00
ac278ca690 Parametros correctos para persona. 2025-05-13 20:18:20 -04:00
97d34f9ad6 Uso de request original 2025-05-13 20:18:09 -04:00
134588c96d Envio de estado de cuotas. 2025-05-13 20:17:53 -04:00
8b6516241d Manejo de contenido 2025-05-13 20:13:15 -04:00
d6e60efcaf Parametros correctos 2025-05-13 20:12:26 -04:00
3e937ab748 Fetch ventas con cuotas pendientes 2025-05-13 20:11:49 -04:00
fa6881d0a9 Formato correcto de fecha y bool 2025-05-13 20:11:02 -04:00
f07c1f1cbd Formato correcto de fecha 2025-05-13 20:10:46 -04:00
148d08089d Estado Cuota y Pago 2025-05-13 20:10:24 -04:00
45b6ee710e Job mas completo 2025-05-13 20:10:12 -04:00
c84277fdc4 Update services 2025-05-13 20:09:50 -04:00
c0024a4a63 Parse body correctly and test fill 2025-05-13 20:03:20 -04:00
308a84a448 Send current request to queue for parameters 2025-05-13 20:02:50 -04:00
91c74bf113 Min log level 2025-05-13 16:17:47 -04:00
024a6eae54 Jobs not being updated 2025-05-13 16:06:09 -04:00
d536342425 No output on wait 2025-05-13 15:58:49 -04:00
e7f3b33850 Wait till next minute after running jobs 2025-05-13 15:53:13 -04:00
c47d94d475 FIX: missing use 2025-05-13 15:49:41 -04:00
ee74fc7588 FIX: esperar al siguiente minuto 2025-05-13 15:47:18 -04:00
5ac324de6a Hora en output 2025-05-13 15:40:32 -04:00
dfb0ff7aea Missing middlewares 2025-05-13 15:16:29 -04:00
6d1a1c914a Wait for execution 2025-05-13 15:15:20 -04:00
b45d03aa7e Reestructura APIClient 2025-05-13 09:32:48 -04:00
4e0b611bcf FIX: Mayuscula 2025-05-13 09:31:51 -04:00
20ea5d021d FIX: missing text 2025-05-12 19:58:20 -04:00
32dc24a783 Newline 2025-05-12 19:54:03 -04:00
95a6aa96e9 Queue 2025-05-12 19:46:31 -04:00
f14cdd2730 Updates 2025-05-12 19:46:09 -04:00
3006adb0f7 Configuracion servicios 2025-05-12 19:44:58 -04:00
d22480dcb8 User edit and delete 2025-05-12 19:44:16 -04:00
425b85e40d Unify cli logs 2025-05-12 19:44:00 -04:00
2c21e48562 FIX: DEPRECATED 2025-05-12 19:43:39 -04:00
8d3ce99be7 Update env sample 2025-05-12 18:32:30 -04:00
35386724b3 FIX: DEPRECATED 2025-05-12 18:07:14 -04:00
1597657f0e FIX: Toku external 2025-05-12 16:35:33 -04:00
c6bbaf3404 FIX: DEPRECATED 2025-05-12 16:08:10 -04:00
9e2d7277b0 Validacion API/external 2025-05-12 16:01:09 -04:00
abe37227ce API/external 2025-05-12 15:47:51 -04:00
32130f0bc2 Usando variables definidas 2025-05-12 14:04:58 -04:00
d78bdaa7f5 Falta ortografia 2025-05-12 13:57:43 -04:00
1266c3859d Migration for Jobs 2025-05-12 13:54:28 -04:00
c5466b2c4d Ignore optionals 2025-05-12 13:15:22 -04:00
6d8e8a9068 Env sample update 2025-05-12 13:06:44 -04:00
4d5b657b92 Manejo de trabajos en cli por php en vez de cron 2025-05-10 12:40:06 -04:00
4ca1616dfc Integracion Toku a flujo 2025-05-10 12:39:31 -04:00
fb7177fd65 Reorden Toku 2025-05-10 12:38:14 -04:00
1486d6cf38 Toku settings 2025-05-10 12:32:01 -04:00
8b2de31e02 Job Queue 2025-05-10 12:30:35 -04:00
61324f159b Toku endpoint 2025-05-10 12:30:21 -04:00
c95e74d574 Controlador Toku 2025-05-09 18:31:00 -04:00
59ecb6cc79 Se agregan fetchs 2025-05-09 18:05:40 -04:00
db84187461 Pruebas de Toku 2025-05-09 18:05:19 -04:00
c2f98c8b0d Excepcion 2025-05-09 18:04:37 -04:00
8d73987ac3 FIX: Cambios a Servicios Toku 2025-05-09 18:04:17 -04:00
400b2754bf FIX: Totales para multipropietario no sumaban correctamente 2025-05-09 13:33:08 -04:00
418becaeda FIX: onChange 2025-05-08 18:15:32 -04:00
679b401101 Servicio Toku para enviar datos 2025-05-08 17:17:49 -04:00
26b6862955 FIX: prueba Servicio Customer 2025-05-08 17:17:24 -04:00
e239669839 FIX: prueba modelo Customer 2025-05-08 17:16:55 -04:00
adc0e52c1e Fix: estructura interface 2025-05-08 17:16:32 -04:00
d1905194bd rut en Customer en formato Toku 2025-05-08 17:16:03 -04:00
a5c1d60819 Servicios para Toku 2025-05-08 16:17:26 -04:00
5ad4fc4038 Tests de Repositories 2025-05-08 16:17:14 -04:00
ca5354a3ee Cambio en namespace 2025-05-08 11:13:23 -04:00
c1ebac6c0c Pruebas de repositories 2025-05-08 11:13:06 -04:00
f742c7ddd0 Pruebas de modelos 2025-05-08 10:45:31 -04:00
5d5f9866bb Modelos para Toku 2025-05-07 20:05:00 -04:00
0866292d84 Migraciones para guardar datos de Toku 2025-05-07 20:04:27 -04:00
e02ed4684f LoggerAwareInterface abstract 2025-05-07 20:04:06 -04:00
8be5f94b7c Log solo los errores fatales. 2025-05-07 20:01:55 -04:00
878b02ee52 SII falla si fecha está en el futuro. 2025-05-07 19:42:39 -04:00
f3e15b34a8 Persona conectada con Propietario 2025-05-07 19:24:33 -04:00
3903551176 FIX: migraciones fallando 2025-05-07 19:23:37 -04:00
43eb8ec758 FIX: no borra todo 2025-05-07 19:22:39 -04:00
a405b15410 Uso de script central de Rut 2025-05-06 10:00:12 -04:00
a2f2d94e64 Docker image con tag 2025-05-06 09:47:54 -04:00
0587b64d65 Docker image 2025-05-06 09:37:23 -04:00
a6b81f1bff FIX: Not needed 2025-05-06 09:15:46 -04:00
4239bafc26 FIX: echo append 2025-05-05 19:33:46 -04:00
6591e9f80e FIX: debian ftp 2025-05-05 19:33:01 -04:00
b57f32c86b FIX: Circular dependency 2025-05-05 19:10:31 -04:00
0e903f99c4 FIX: Circular dependency 2025-05-05 19:08:44 -04:00
186cd0f5b8 Reparaciones con Prueba 2025-05-05 19:01:15 -04:00
167d8e1ab7 PHP Dom en PHP 8.4 2025-05-05 19:00:41 -04:00
46802507a7 SII como provider de UF 2025-05-05 18:16:18 -04:00
aaf2ed7612 UF service en Venta 2025-05-05 18:15:48 -04:00
3ced9e40b1 const en Money y multi provider 2025-05-05 18:15:29 -04:00
594cb68b09 Provider SII 2025-05-05 18:14:50 -04:00
af68c4b8ec Ine null date 2025-05-05 18:14:20 -04:00
ea8f483dd5 FIX: Repository UF 2025-05-05 18:13:55 -04:00
5f53c77a1f Repository::getConnection 2025-05-05 18:13:12 -04:00
b9adb9108b Provider null date 2025-05-05 18:12:58 -04:00
8be085222a Not Allowed template 2025-05-05 16:46:41 -04:00
d1e4314b35 Valor de UF de hoy cuando no se encuentra valor. 2025-05-05 16:46:14 -04:00
7d04b406ab Grabar UF y capacidad de obtener hoy. 2025-05-05 16:45:43 -04:00
972e57b6f1 Mejora en respuesta cuando no existe algun valor. 2025-05-05 16:43:24 -04:00
5f63bdbf4a Fecha maxima de venta es hoy 2025-05-05 16:41:08 -04:00
a8325c3310 Uso de NumberInput en Edit BonoPie 2025-05-05 15:55:23 -04:00
7e54b72587 NumberInput, para formateo de numeros 2025-05-05 15:45:07 -04:00
ebe31a3d3d Guardar UF en DB 2025-05-05 15:40:55 -04:00
db6445bcf3 Cleanup View 2025-05-05 15:40:26 -04:00
4e1901b7c8 FatalErrors 2025-05-05 15:40:05 -04:00
c3316029c9 Se borra migracion duplicada 2025-05-05 14:01:39 -04:00
cbfc796685 Merge remote-tracking branch 'origin/feature/cierres' into feature/cierres 2025-05-05 11:35:29 -04:00
da56192f97 Formateo de numeros en JS 2025-04-30 23:36:32 -04:00
b5d08620f9 Unidades que no son departamentos 2025-04-30 17:13:40 -04:00
c92b07ee6f Excepcion correcta 2025-04-30 17:13:26 -04:00
ee6956d417 Reorden 2025-04-30 16:18:20 -04:00
21d5e2d03b Api en archivo separado 2025-04-30 16:18:00 -04:00
73a742c01e Nada en public 2025-04-30 10:51:47 -04:00
dd42c12d49 Orden 2025-04-30 10:38:20 -04:00
41ea5f5c15 Update prueba 2025-04-30 10:38:05 -04:00
eeb6f5bcd1 Se agrega condicion 2025-04-30 10:37:57 -04:00
2680f51167 Correccion migracion 2025-04-30 10:37:41 -04:00
019d57a0b0 Nuevas pruebas 2025-04-30 01:12:23 -04:00
1a400d9a5c Watcher solo para unit tests 2025-04-30 01:12:09 -04:00
6276f87274 Pruebas nuevas 2025-04-30 00:14:38 -04:00
28c93a42bc Logs de pruebas 2025-04-30 00:14:24 -04:00
4ff5d28522 Nuevas pruebas 2025-04-29 23:57:59 -04:00
a93642c55d Actualizacion de pruebas con extensiones 2025-04-29 23:57:49 -04:00
87c0d8c8d9 Se mueve todo a extension de pruebas 2025-04-29 23:55:51 -04:00
dd1741a930 Broker test 2025-04-29 23:21:19 -04:00
ad0fd82a9e Assert nuevo 2025-04-29 23:21:13 -04:00
bae5c1740d No mas require 2025-04-29 23:19:05 -04:00
f5f1482b7a Autoload para pruebas 2025-04-29 23:18:55 -04:00
4bd5fe16df Comandos para correr pruebas y consola 2025-04-29 23:18:18 -04:00
61845fbd05 Ignorar datos de pruebas 2025-04-29 22:26:26 -04:00
f8ac0f14f0 Abstracts 2025-04-29 22:25:32 -04:00
acb7a1336d Coverage lento e innecesario 2025-04-29 22:25:11 -04:00
8af56137a8 Seeds al migrar 2025-04-29 21:51:19 -04:00
c3247838b3 Namespace test Servicio Valor 2025-04-29 21:43:21 -04:00
dd82ac6bb7 Tests Home 2025-04-29 21:42:57 -04:00
2acf0362fa Ambiente de testeo 2025-04-29 21:41:49 -04:00
e6892ee085 Valor de PU cuando unidad no tiene valor 2025-04-29 13:01:57 -04:00
86b8d6b3c7 Limpieza 2025-04-29 13:01:21 -04:00
53115b085f Asegurarse que el valor entregado a Pago es en pesos. 2025-04-29 11:29:23 -04:00
c3b7427f60 Cambio en nombre de metodo y uso de valor maximo para UF 2025-04-29 11:20:49 -04:00
5d939f970b Valor con pruebas 2025-04-28 20:20:43 -04:00
4845801b27 Uso de script central de rut 2025-04-28 19:00:40 -04:00
d5bf9a7660 Digito verificador 2025-04-28 18:59:37 -04:00
795dda868b Ya no se incluye UF/m² y se transforman en numeros las UF 2025-04-25 20:03:11 -04:00
53a3633dc7 Menu -> Agregar Venta separado 2025-04-25 20:02:24 -04:00
0143fd11ac Se pasan datos a EmptyResult en base- 2025-04-25 19:41:42 -04:00
55745a8d0a EmptyResult ahora puede llevar los datos. 2025-04-25 19:41:23 -04:00
2a1930c5f7 FIX: Propiedad con unidad_principal 2025-04-25 19:25:16 -04:00
31f49dddb6 FIX: unidad_principal no tiene valor por defecto. 2025-04-25 17:36:12 -04:00
b4ca59fb6d Optimizacion de obtencion de datos. 2025-04-24 19:23:39 -04:00
d910f3eb69 FIX: Propiedad sin unidad_principal 2025-04-24 18:54:54 -04:00
555cdb7138 Promociones en misma tabla para tipo 2025-04-24 18:50:04 -04:00
65088da2f5 Promociones en misma tabla para tipo 2025-04-23 16:49:52 -04:00
966b341b65 Listado de promociones 2025-04-22 18:34:23 -04:00
90b05ca25c Se elimina la comision del excel 2025-04-22 16:28:13 -04:00
bb3a2fffa1 Cuando no existen promociones 2025-04-22 15:38:30 -04:00
8a5e41a722 Normalizacion con profundidad 2025-04-22 15:31:55 -04:00
5736a346e7 Valor debiese ser el último precio. 2025-04-22 15:24:11 -04:00
4f4e69f0c3 FIX: no tiene precio ahora, solo valor 2025-04-22 15:19:25 -04:00
00deebeaa8 FIX: faltaba valor 2025-04-22 15:19:08 -04:00
aee0754b5a Simplificacion de retorno de ventas por unidades 2025-04-22 15:18:59 -04:00
eabdab23c3 Simplificacion de retorno de ventas por unidades 2025-04-22 13:08:15 -04:00
5147450ed6 Manejo de excepciones 2025-04-22 13:07:52 -04:00
ed96f25475 Mayor orden 2025-04-22 11:49:34 -04:00
d5a3512852 Barras de progreso 2025-04-22 11:35:56 -04:00
d6730cd020 Cambio en link 2025-04-22 09:29:14 -04:00
c7dddc818c Definicion de variables una sola vez 2025-04-22 09:28:45 -04:00
33b4182bd3 Optimizacion de queries a cargar de una sola vez 2025-04-22 09:28:12 -04:00
fc776e6cec Ruta para Ventas por unidades 2025-04-21 19:43:20 -04:00
5d79ea83c3 Mostrar valor de venta para unidades vendidas 2025-04-21 19:43:01 -04:00
c34048a53a Ventas por unidades 2025-04-21 19:41:20 -04:00
f7af93b815 Throw Read 2025-04-21 19:40:26 -04:00
993e4ff3b8 Merge branch 'develop' into feature/cierres 2025-04-11 13:35:13 -04:00
bc49ba7629 FIX: Busqueda no funcionaba 2025-04-09 09:29:53 -04:00
3c2b486083 Se agregan columnas y el calculo de promociones de tipo fijo 2025-04-08 19:04:46 -04:00
76f69f3bda Optimizacion simple 2025-04-08 18:38:18 -04:00
8ba3c456b6 Link a contrato en vez del proyecto 2025-04-08 18:35:07 -04:00
98b18fab3e Cambios solicitados 2025-04-08 18:30:14 -04:00
12a4831887 Merge branch 'develop' into feature/cierres 2025-04-04 13:23:00 -03:00
da46914de4 Promociones en Contrato 2025-04-04 12:56:49 -03:00
596bc71cf8 Mejoras UI 2025-04-04 12:54:51 -03:00
7f8e4ea943 FIX: query fallaba 2025-04-04 12:36:03 -03:00
5456485f71 FIX: ya no existe relacion con contratos 2025-04-04 12:08:46 -03:00
836503a71b Menus nuevos 2025-04-04 12:08:24 -03:00
4df0cca675 Filtro en excel 2025-04-04 11:53:25 -03:00
00a0adb4ac Espacio mas ajustado 2025-04-04 11:53:11 -03:00
037fcd60f3 Orden de queries 2025-04-04 11:52:50 -03:00
7a97fc9dfe Precios con promociones para listado brokers 2025-04-03 17:22:38 -03:00
7b2df74e4d Promociones para cada subdivicion 2025-04-03 17:22:11 -03:00
b5d6d0acb9 Mostrar porcentajes en venta 2025-04-03 13:56:11 -03:00
8a1e6a7761 Conecciones de Promociones 2025-04-03 13:15:56 -03:00
ced673e452 Correcto nombre de tabla 2025-04-03 13:12:57 -03:00
8a7a1d4e64 Merge branch 'develop' into feature/cierres 2025-03-27 11:44:54 -03:00
9be20ab1cd UF 0 o nula actualizadas para Pago y Pie 2025-03-26 16:54:53 -03:00
1c40f18624 Pagos sin uf retornan 0 2025-03-26 16:49:27 -03:00
db36549699 Agregar Pie 2025-03-26 16:41:54 -03:00
4ce83fb270 Merge branch 'develop' into feature/cierres 2025-03-26 15:42:47 -03:00
b191a01313 Promociones 2025-03-25 19:22:38 -03:00
d3b0026ca4 Agregar, editar y eliminar promociones 2025-03-18 19:13:47 -03:00
2b3f476df7 Agregar, editar y eliminar promociones 2025-03-18 19:12:59 -03:00
39c148b7b3 Cambio nombre archivo 2025-03-17 23:03:06 -03:00
bae0f1f555 Separacion de Promocion de Contrato y Precio
"Simplificacion" de datos en listado de precios
2025-03-17 22:49:48 -03:00
2e49e2c947 Listados separados por hojas (tabs) 2025-03-13 13:16:20 -03:00
68aebdb4fe Listado de Precios para Contrato Broker 2025-03-13 12:18:08 -03:00
346001db8e SearchBuilder configuration centralizada
FIX: CentroCosto TipoCuenta
2025-03-13 09:33:42 -03:00
8b04eb262f FIX: Editar datos Broker 2025-03-12 18:31:21 -03:00
7c7c8315e2 Editar Brokers y sus contratos 2025-03-11 17:41:11 -03:00
510e05e5ca FIX: rut con otros caracteres y maximo largo 2025-03-07 17:26:36 -03:00
5055d2703c Broker Contact 2025-03-07 17:11:59 -03:00
2bc30ab9e8 Formatear porcentajes menores a 1 2025-03-07 17:11:15 -03:00
c7ee440e03 Listado de brokers 2025-03-06 20:34:43 -03:00
18dd8c4ec0 Merge branch 'develop' into feature/cierres 2025-03-06 16:23:58 -03:00
8ea4995f6b Contratos desde proyectos 2025-03-03 21:46:53 -03:00
aeeca65d94 Correcciones 2025-03-03 21:41:43 -03:00
5f69069aa0 Rutas Reservations 2025-03-03 16:53:36 -03:00
095a65a643 Cleanup por recomendaciones 2025-03-03 16:37:40 -03:00
928d2e57be Merge branch 'develop' into feature/cierres 2025-03-03 15:32:25 -03:00
2a0335f834 Reservation Controller 2025-03-03 15:21:18 -03:00
9ccf53fa4e Reservation Service 2025-03-03 15:21:12 -03:00
ef54c36edc Cleanup 2025-03-03 14:56:18 -03:00
4aa88d5164 Rutas API Contratos 2025-03-03 11:26:45 -03:00
8ea13c3efd API Contratos 2025-03-03 10:47:48 -03:00
12e3d7ed3b Servicio Contratos 2025-03-01 13:26:55 -03:00
a7fc89ac29 Merge branch 'develop' into feature/cierres 2025-02-24 21:36:35 -03:00
a71df4e70d Controlador y ruta de operadores para API 2025-02-24 12:41:50 -03:00
f17b7a758a withJson con error 2025-02-24 12:41:34 -03:00
7fb28cd44c Servicio operadores 2025-02-24 12:41:13 -03:00
a44bd610ad Excepciones de servicios 2025-02-24 12:41:00 -03:00
28bba8a438 Actualizacion de Modelos 2025-02-24 12:40:40 -03:00
0ec6ebdafe Actualizacion de Repos 2025-02-24 12:39:42 -03:00
3ebe256a66 Actualizacion de migraciones 2025-02-24 12:39:25 -03:00
9d135e2c26 Base de Datos 2025-02-18 16:02:10 -03:00
179 changed files with 615 additions and 7729 deletions

View File

@ -2,15 +2,15 @@ FROM php:8.4-cli
ENV TZ "${TZ}" ENV TZ "${TZ}"
ENV APP_NAME "${APP_NAME}" ENV APP_NAME "${APP_NAME}"
ENV API_URL "${API_URL}"
RUN apt-get update && apt-get install -y --no-install-recommends cron rsyslog nano beanstalkd \ RUN apt-get update && apt-get install -y --no-install-recommends cron rsyslog nano && rm -r /var/lib/apt/lists/*
&& rm -r /var/lib/apt/lists/*
RUN pecl install xdebug-3.4.2 \ RUN pecl install xdebug-3.4.2 \
&& docker-php-ext-enable xdebug \ && docker-php-ext-enable xdebug \
&& echo $TZ > /etc/timezone && echo $TZ > /etc/timezone
COPY --chmod=550 ./cli/start_command /root/start_command COPY --chmod=550 ./cli/entrypoint /root/entrypoint
COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini
COPY ./php-timezone.ini /usr/local/etc/php/conf.d/docker-php-timezone.ini COPY ./php-timezone.ini /usr/local/etc/php/conf.d/docker-php-timezone.ini
@ -19,4 +19,4 @@ WORKDIR /code/bin
COPY --chmod=644 ./cli/crontab /var/spool/cron/crontabs/root COPY --chmod=644 ./cli/crontab /var/spool/cron/crontabs/root
CMD [ "/root/start_command" ] CMD [ "/root/entrypoint" ]

View File

@ -3,7 +3,7 @@ FROM php:8.4-fpm
ENV TZ=America/Santiago ENV TZ=America/Santiago
RUN apt-get update && apt-get install -y --no-install-recommends libzip-dev libicu-dev git \ RUN apt-get update && apt-get install -y --no-install-recommends libzip-dev libicu-dev git \
libpng-dev unzip tzdata libxml2-dev beanstalkd \ libpng-dev unzip tzdata libxml2-dev \
&& rm -r /var/lib/apt/lists/* \ && rm -r /var/lib/apt/lists/* \
&& docker-php-ext-install pdo pdo_mysql zip intl gd bcmath dom \ && docker-php-ext-install pdo pdo_mysql zip intl gd bcmath dom \
&& pecl install xdebug-3.4.2 \ && pecl install xdebug-3.4.2 \

0
app/bin/console Executable file → Normal file
View File

0
app/bin/integration_tests Executable file → Normal file
View File

0
app/bin/performance_tests Executable file → Normal file
View File

0
app/bin/unit_tests Executable file → Normal file
View File

View File

@ -26,7 +26,7 @@ abstract class Model implements Define\Model
public function jsonSerialize(): mixed public function jsonSerialize(): mixed
{ {
return [ return [
'id' => $this->id ?? '', 'id' => $this->id,
...$this->jsonComplement() ...$this->jsonComplement()
]; ];
} }

View File

@ -1,10 +0,0 @@
<?php
namespace Incoviba\Common\Ideal\Service;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
abstract class Repository extends Ideal\Service
{
abstract public function getRepository(): Define\Repository;
}

View File

@ -64,10 +64,10 @@ class Select extends Ideal\Query implements Define\Query\Select
public function having(array|string $conditions): Select public function having(array|string $conditions): Select
{ {
if (is_string($conditions)) { if (is_string($conditions)) {
return $this->addHaving($conditions); return $this->addCondition($conditions);
} }
foreach ($conditions as $condition) { foreach ($conditions as $condition) {
$this->addHaving($condition); $this->addCondition($condition);
} }
return $this; return $this;
} }

View File

@ -2,9 +2,7 @@
namespace Incoviba\Common\Implement\Repository; namespace Incoviba\Common\Implement\Repository;
use Closure; use Closure;
use Exception;
use Incoviba\Common\Define; use Incoviba\Common\Define;
use Incoviba\Common\Implement\Exception\EmptyResult;
class Factory implements Define\Repository\Factory class Factory implements Define\Repository\Factory
{ {
@ -22,16 +20,8 @@ class Factory implements Define\Repository\Factory
return $this; return $this;
} }
/**
* @return mixed
* @throws EmptyResult
*/
public function run(): mixed public function run(): mixed
{ {
try { return call_user_func_array($this->callable, $this->args);
return call_user_func_array($this->callable, $this->args);
} catch (Exception $exception) {
throw new EmptyResult($exception->getMessage(), $exception);
}
} }
} }

View File

@ -8,13 +8,11 @@
"ext-gd": "*", "ext-gd": "*",
"ext-openssl": "*", "ext-openssl": "*",
"ext-pdo": "*", "ext-pdo": "*",
"ext-sockets": "*",
"berrnd/slim-blade-view": "^1", "berrnd/slim-blade-view": "^1",
"guzzlehttp/guzzle": "^7", "guzzlehttp/guzzle": "^7",
"monolog/monolog": "^3", "monolog/monolog": "^3",
"nyholm/psr7": "^1", "nyholm/psr7": "^1",
"nyholm/psr7-server": "^1", "nyholm/psr7-server": "^1",
"pda/pheanstalk": "^7.0",
"php-di/php-di": "^7", "php-di/php-di": "^7",
"php-di/slim-bridge": "^3", "php-di/slim-bridge": "^3",
"phpoffice/phpspreadsheet": "^3", "phpoffice/phpspreadsheet": "^3",

View File

@ -1,496 +0,0 @@
; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[fcgi]
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or NONE) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of the child processes. This can be used only if the master
; process running user is root. It is set after the child process is created.
; The user and group can be specified either by their name or by their numeric
; IDs.
; Note: If the user is root, the executable needs to be started with
; --allow-to-run-as-root option to work.
; Default Values: The user is set to master process running user by default.
; If the group is not set, the user's group is used.
user = www-data
group = www-data
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
;listen = 127.0.0.1:9000
listen = 9090
; Set listen(2) backlog.
; Default Value: 511 (-1 on Linux, FreeBSD and OpenBSD)
;listen.backlog = 511
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. The owner
; and group can be specified either by name or by their numeric IDs.
; Default Values: Owner is set to the master process running user. If the group
; is not set, the owner's group is used. Mode is set to 0660.
;listen.owner = www-data
;listen.group = www-data
;listen.mode = 0660
; When POSIX Access Control Lists are supported you can set them using
; these options, value is a comma separated list of user/group names.
; When set, listen.owner and listen.group are ignored
;listen.acl_users =
;listen.acl_groups =
; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
;listen.allowed_clients = 127.0.0.1
; Set the associated the route table (FIB). FreeBSD only
; Default Value: -1
;listen.setfib = 1
; Specify the nice(2) priority to apply to the pool processes (only if set)
; The value can vary from -19 (highest priority) to 20 (lower priority)
; Note: - It will only work if the FPM master process is launched as root
; - The pool processes will inherit the master process priority
; unless it specified otherwise
; Default Value: no set
; process.priority = -19
; Set the process dumpable flag (PR_SET_DUMPABLE prctl for Linux or
; PROC_TRACE_CTL procctl for FreeBSD) even if the process user
; or group is different than the master process user. It allows to create process
; core dump and ptrace the process for the pool user.
; Default Value: no
; process.dumpable = yes
; Choose how the process manager will control the number of child processes.
; Possible Values:
; static - a fixed number (pm.max_children) of child processes;
; dynamic - the number of child processes are set dynamically based on the
; following directives. With this process management, there will be
; always at least 1 children.
; pm.max_children - the maximum number of children that can
; be alive at the same time.
; pm.start_servers - the number of children created on startup.
; pm.min_spare_servers - the minimum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is less than this
; number then some children will be created.
; pm.max_spare_servers - the maximum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is greater than this
; number then some children will be killed.
; pm.max_spawn_rate - the maximum number of rate to spawn child
; processes at once.
; ondemand - no children are created at startup. Children will be forked when
; new requests will connect. The following parameter are used:
; pm.max_children - the maximum number of children that
; can be alive at the same time.
; pm.process_idle_timeout - The number of seconds after which
; an idle process will be killed.
; Note: This value is mandatory.
pm = ondemand
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 2
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: (min_spare_servers + max_spare_servers) / 2
;pm.start_servers = 2
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
;pm.min_spare_servers = 1
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
;pm.max_spare_servers = 3
; The number of rate to spawn child processes at once.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
; Default Value: 32
;pm.max_spawn_rate = 32
; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;
pm.process_idle_timeout = 10s
; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
;pm.max_requests = 500
; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. It shows the following information:
; pool - the name of the pool;
; process manager - static, dynamic or ondemand;
; start time - the date and time FPM has started;
; start since - number of seconds since FPM has started;
; accepted conn - the number of request accepted by the pool;
; listen queue - the number of request in the queue of pending
; connections (see backlog in listen(2));
; max listen queue - the maximum number of requests in the queue
; of pending connections since FPM has started;
; listen queue len - the size of the socket queue of pending connections;
; idle processes - the number of idle processes;
; active processes - the number of active processes;
; total processes - the number of idle + active processes;
; max active processes - the maximum number of active processes since FPM
; has started;
; max children reached - number of times, the process limit has been reached,
; when pm tries to start more children (works only for
; pm 'dynamic' and 'ondemand');
; Value are updated in real time.
; Example output:
; pool: www
; process manager: static
; start time: 01/Jul/2011:17:53:49 +0200
; start since: 62636
; accepted conn: 190460
; listen queue: 0
; max listen queue: 1
; listen queue len: 42
; idle processes: 4
; active processes: 11
; total processes: 15
; max active processes: 12
; max children reached: 0
;
; By default the status page output is formatted as text/plain. Passing either
; 'html', 'xml' or 'json' in the query string will return the corresponding
; output syntax. Example:
; http://www.foo.bar/status
; http://www.foo.bar/status?json
; http://www.foo.bar/status?html
; http://www.foo.bar/status?xml
;
; By default the status page only outputs short status. Passing 'full' in the
; query string will also return status for each pool process.
; Example:
; http://www.foo.bar/status?full
; http://www.foo.bar/status?json&full
; http://www.foo.bar/status?html&full
; http://www.foo.bar/status?xml&full
; The Full status returns for each process:
; pid - the PID of the process;
; state - the state of the process (Idle, Running, ...);
; start time - the date and time the process has started;
; start since - the number of seconds since the process has started;
; requests - the number of requests the process has served;
; request duration - the duration in µs of the requests;
; request method - the request method (GET, POST, ...);
; request URI - the request URI with the query string;
; content length - the content length of the request (only with POST);
; user - the user (PHP_AUTH_USER) (or '-' if not set);
; script - the main script called (or '-' if not set);
; last request cpu - the %cpu the last request consumed
; it's always 0 if the process is not in Idle state
; because CPU calculation is done when the request
; processing has terminated;
; last request memory - the max amount of memory the last request consumed
; it's always 0 if the process is not in Idle state
; because memory calculation is done when the request
; processing has terminated;
; If the process is in Idle state, then information is related to the
; last request the process has served. Otherwise information is related to
; the current request being served.
; Example output:
; ************************
; pid: 31330
; state: Running
; start time: 01/Jul/2011:17:53:49 +0200
; start since: 63087
; requests: 12808
; request duration: 1250261
; request method: GET
; request URI: /test_mem.php?N=10000
; content length: 0
; user: -
; script: /home/fat/web/docs/php/test_mem.php
; last request cpu: 0.00
; last request memory: 0
;
; Note: There is a real-time FPM status monitoring sample web page available
; It's available in: /usr/local/share/php/fpm/status.html
;
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;pm.status_path = /status
; The address on which to accept FastCGI status request. This creates a new
; invisible pool that can handle requests independently. This is useful
; if the main pool is busy with long running requests because it is still possible
; to get the status before finishing the long running requests.
;
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Default Value: value of the listen option
;pm.status_listen = 127.0.0.1:9001
; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page. This could be used to test from outside
; that FPM is alive and responding, or to
; - create a graph of FPM availability (rrd or such);
; - remove a server from a group if it is not responding (load balancing);
; - trigger alerts for the operating team (24/7).
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;ping.path = /ping
; This directive may be used to customize the response of a ping request. The
; response is formatted as text/plain with a 200 response code.
; Default Value: pong
;ping.response = pong
; The access log file
; Default: not set
;access.log = log/$pool.access.log
access.log = /proc/self/fd/2
; The access log format.
; The following syntax is allowed
; %%: the '%' character
; %C: %CPU used by the request
; it can accept the following format:
; - %{user}C for user CPU only
; - %{system}C for system CPU only
; - %{total}C for user + system CPU (default)
; %d: time taken to serve the request
; it can accept the following format:
; - %{seconds}d (default)
; - %{milliseconds}d
; - %{milli}d
; - %{microseconds}d
; - %{micro}d
; %e: an environment variable (same as $_ENV or $_SERVER)
; it must be associated with embraces to specify the name of the env
; variable. Some examples:
; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
; %f: script filename
; %l: content-length of the request (for POST request only)
; %m: request method
; %M: peak of memory allocated by PHP
; it can accept the following format:
; - %{bytes}M (default)
; - %{kilobytes}M
; - %{kilo}M
; - %{megabytes}M
; - %{mega}M
; %n: pool name
; %o: output header
; it must be associated with embraces to specify the name of the header:
; - %{Content-Type}o
; - %{X-Powered-By}o
; - %{Transfert-Encoding}o
; - ....
; %p: PID of the child that serviced the request
; %P: PID of the parent of the child that serviced the request
; %q: the query string
; %Q: the '?' character if query string exists
; %r: the request URI (without the query string, see %q and %Q)
; %R: remote IP address
; %s: status (response code)
; %t: server time the request was received
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; The strftime(3) format must be encapsulated in a %{<strftime_format>}t tag
; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
; %T: time the log has been written (the request has finished)
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; The strftime(3) format must be encapsulated in a %{<strftime_format>}t tag
; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
; %u: basic auth user if specified in Authorization header
;
; Default: "%R - %u %t \"%m %r\" %s"
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{milli}d %{kilo}M %C%%"
; A list of request_uri values which should be filtered from the access log.
;
; As a security precaution, this setting will be ignored if:
; - the request method is not GET or HEAD; or
; - there is a request body; or
; - there are query parameters; or
; - the response code is outwith the successful range of 200 to 299
;
; Note: The paths are matched against the output of the access.format tag "%r".
; On common configurations, this may look more like SCRIPT_NAME than the
; expected pre-rewrite URI.
;
; Default Value: not set
;access.suppress_path[] = /ping
;access.suppress_path[] = /health_check.php
; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
;slowlog = log/$pool.log.slow
; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_slowlog_timeout = 0
; Depth of slow log stack trace.
; Default Value: 20
;request_slowlog_trace_depth = 20
; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_terminate_timeout = 0
; The timeout set by 'request_terminate_timeout' ini option is not engaged after
; application calls 'fastcgi_finish_request' or when application has finished and
; shutdown functions are being called (registered via register_shutdown_function).
; This option will enable timeout limit to be applied unconditionally
; even in such cases.
; Default Value: no
;request_terminate_timeout_track_finished = no
; Set open file descriptor rlimit.
; Default Value: system defined value
;rlimit_files = 1024
; Set max core size rlimit.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0
; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
; Note: chrooting is a great security feature and should be used whenever
; possible. However, all PHP paths will be relative to the chroot
; (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot =
; Chdir to this directory at the start.
; Note: relative path can be used.
; Default Value: current directory or / when chroot
;chdir = /var/www
; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environment, this can cause some delay in the page
; process time (several ms).
; Default Value: no
;catch_workers_output = yes
catch_workers_output = yes
; Decorate worker output with prefix and suffix containing information about
; the child that writes to the log and if stdout or stderr is used as well as
; log level and time. This options is used only if catch_workers_output is yes.
; Settings to "no" will output data as written to the stdout or stderr.
; Default value: yes
;decorate_workers_output = no
decorate_workers_output = no
; Clear environment in FPM workers
; Prevents arbitrary environment variables from reaching FPM worker processes
; by clearing the environment in workers before env vars specified in this
; pool configuration are added.
; Setting to "no" will make all environment variables available to PHP code
; via getenv(), $_ENV and $_SERVER.
; Default Value: yes
;clear_env = no
clear_env = no
; Limits the extensions of the main script FPM will allow to parse. This can
; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
; execute php code.
; Note: set an empty value to allow all extensions.
; Default Value: .php
;security.limit_extensions = .php .php3 .php4 .php5 .php7
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
; php_value/php_flag - you can set classic ini defines which can
; be overwritten from PHP call 'ini_set'.
; php_admin_value/php_admin_flag - these directives won't be overwritten by
; PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.
; Note: path INI options can be relative and will be expanded with the prefix
; (pool, global or /usr/local)
; Default Value: nothing is defined by default except the values in php.ini and
; specified at startup with the -d argument
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
use Phinx\Migration\AbstractMigration; use Phinx\Migration\AbstractMigration;
final class CreateReservations extends AbstractMigration final class CreateReservation extends AbstractMigration
{ {
/** /**
* Change Method. * Change Method.
@ -23,11 +23,9 @@ final class CreateReservations extends AbstractMigration
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';"); $this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';"); $this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
$this->table('reservations') $this->table('reservation')
->addColumn('project_id', 'integer', ['signed' => false, 'null' => false])
->addColumn('buyer_rut', 'integer', ['signed' => false, 'null' => false]) ->addColumn('buyer_rut', 'integer', ['signed' => false, 'null' => false])
->addColumn('date', 'date', ['null' => false]) ->addColumn('date', 'date', ['null' => false])
->addForeignKey('project_id', 'proyecto', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
->addForeignKey('buyer_rut', 'personas', 'rut', ['delete' => 'cascade', 'update' => 'cascade']) ->addForeignKey('buyer_rut', 'personas', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
->create(); ->create();

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
use Phinx\Migration\AbstractMigration; use Phinx\Migration\AbstractMigration;
final class CreateReservationDetails extends AbstractMigration final class CreateReservationDatas extends AbstractMigration
{ {
/** /**
* Change Method. * Change Method.
@ -23,13 +23,11 @@ final class CreateReservationDetails extends AbstractMigration
$this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';"); $this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';");
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';"); $this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
$this->table('reservation_details') $this->table('reservation_data')
->addColumn('reservation_id', 'integer', ['signed' => false, 'null' => false]) ->addColumn('reservation_id', 'integer', ['signed' => false, 'null' => false])
->addColumn('type', 'integer', ['length' => 1, 'signed' => false, 'null' => false]) ->addColumn('type', 'integer', ['length' => 1, 'signed' => false, 'null' => false])
->addColumn('reference_id', 'integer', ['signed' => false, 'null' => false]) ->addColumn('reference_id', 'integer', ['signed' => false, 'null' => false])
->addColumn('value', 'decimal', ['precision' => 10, 'scale' => 2, 'signed' => false, 'default' => null, 'null' => true]) ->addColumn('value', 'decimal', ['precision' => 10, 'scale' => 2, 'signed' => false, 'default' => 0.00, 'null' => true])
->addForeignKey('reservation_id', 'reservations', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
->addIndex(['reservation_id', 'type', 'reference_id'], ['unique' => true, 'name' => 'idx_reservation_details'])
->create(); ->create();
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;'); $this->execute('SET unique_checks=1; SET foreign_key_checks=1;');

View File

@ -27,7 +27,7 @@ final class CreateReservationStates extends AbstractMigration
->addColumn('reservation_id', 'integer', ['signed' => false, 'null' => false]) ->addColumn('reservation_id', 'integer', ['signed' => false, 'null' => false])
->addColumn('date', 'date', ['null' => false]) ->addColumn('date', 'date', ['null' => false])
->addColumn('type', 'integer', ['length' => 3, 'null' => false, 'default' => 0]) ->addColumn('type', 'integer', ['length' => 3, 'null' => false, 'default' => 0])
->addForeignKey('reservation_id', 'reservations', 'id', ['delete' => 'cascade', 'update' => 'cascade']) ->addForeignKey('reservation_id', 'reservation', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
->create(); ->create();
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;'); $this->execute('SET unique_checks=1; SET foreign_key_checks=1;');

View File

@ -1,36 +0,0 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateTokuAccounts extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
$this->table('toku_accounts')
->addColumn('sociedad_rut', 'integer', ['limit' => 8, 'signed' => false, 'null' => false])
->addColumn('toku_id', 'string', ['length' => 255, 'null' => false])
->addColumn('account_key', 'string', ['length' => 255, 'null' => false])
->addColumn('enabled', 'boolean', ['default' => true])
->addTimestamps()
#->addForeignKey('sociedad_rut', 'inmobiliaria', 'rut', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
->addIndex(['toku_id'], ['unique' => true])
->create();
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
}
}

View File

@ -1,26 +0,0 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class ChangeTelefonoSizeInPropietario extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$this->table('propietario')
->changeColumn('telefono', 'biginteger', ['null' => true, 'signed' => false, 'default' => null])
->update();
}
}

View File

@ -1,29 +0,0 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddCommentsToEstadoCierre extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$this->table('estado_cierre_comentarios')
->addColumn('estado_cierre_id', 'integer', ['signed' => false])
->addColumn('fecha', 'datetime', ['default' => 'CURRENT_TIMESTAMP'])
->addColumn('comments', 'text')
->addForeignKey('estado_cierre_id', 'estado_cierre', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
->create();
}
}

View File

@ -7,5 +7,4 @@ $app->group('/toku', function($app) {
$app->get('/test[/]', [Toku::class, 'test']); $app->get('/test[/]', [Toku::class, 'test']);
$app->delete('/reset[/]', [Toku::class, 'reset']); $app->delete('/reset[/]', [Toku::class, 'reset']);
$app->post('/enqueue[/]', [Toku::class, 'enqueue']); $app->post('/enqueue[/]', [Toku::class, 'enqueue']);
$app->post('/update[/{type}[/]]', [Toku::class, 'update']);
}); });

View File

@ -1,7 +0,0 @@
<?php
use Incoviba\Controller\API\Personas;
//$app->group('/personas', function($app) {});
$app->group('/persona/{rut}', function($app) {
$app->get('[/]', [Personas::class, 'get']);
});

View File

@ -30,5 +30,4 @@ $app->group('/proyecto/{proyecto_id}', function($app) {
$app->post('/edit[/]', [Proyectos::class, 'terreno']); $app->post('/edit[/]', [Proyectos::class, 'terreno']);
}); });
$app->get('/brokers', [Proyectos::class, 'brokers']); $app->get('/brokers', [Proyectos::class, 'brokers']);
$app->get('/promotions', [Proyectos::class, 'promotions']);
}); });

View File

@ -2,9 +2,9 @@
use Incoviba\Controller\API\Queues; use Incoviba\Controller\API\Queues;
$app->group('/queue', function($app) { $app->group('/queue', function($app) {
#$app->get('/jobs[/]', [Queues::class, 'jobs']); $app->get('/jobs[/]', [Queues::class, 'jobs']);
$app->group('/run', function($app) { $app->group('/run', function($app) {
#$app->get('/{job_id:[0-9]+}[/]', [Queues::class, 'run']); $app->get('/{job_id:[0-9]+}[/]', [Queues::class, 'run']);
$app->get('[/]', Queues::class); $app->get('[/]', Queues::class);
}); });
}); });

View File

@ -2,7 +2,6 @@
use Incoviba\Controller\API\Ventas\Precios; use Incoviba\Controller\API\Ventas\Precios;
$app->group('/precios', function($app) { $app->group('/precios', function($app) {
$app->post('/import[/]', [Precios::class, 'import']);
$app->post('[/]', [Precios::class, 'proyecto']); $app->post('[/]', [Precios::class, 'proyecto']);
}); });
$app->group('/precio', function($app) { $app->group('/precio', function($app) {

View File

@ -3,19 +3,10 @@ use Incoviba\Controller\API\Ventas\Reservations;
$app->group('/reservations', function($app) { $app->group('/reservations', function($app) {
$app->post('/add[/]', [Reservations::class, 'add']); $app->post('/add[/]', [Reservations::class, 'add']);
$app->group('/project/{project_id}', function($app) {
$app->get('/active[/]', [Reservations::class, 'active']);
$app->get('/pending[/]', [Reservations::class, 'pending']);
$app->get('/rejected[/]', [Reservations::class, 'rejected']);
});
$app->get('[/]', Reservations::class); $app->get('[/]', Reservations::class);
}); });
$app->post('/reservation/add[/]', [Reservations::class, 'addOne']);
$app->group('/reservation/{reservation_id}', function($app) { $app->group('/reservation/{reservation_id}', function($app) {
$app->get('/approve[/]', [Reservations::class, 'approve']);
$app->get('/reject[/]', [Reservations::class, 'reject']);
$app->post('/edit[/]', [Reservations::class, 'edit']); $app->post('/edit[/]', [Reservations::class, 'edit']);
$app->delete('/remove[/]', [Reservations::class, 'remove']);
$app->delete('[/]', [Reservations::class, 'delete']); $app->delete('[/]', [Reservations::class, 'delete']);
$app->get('[/]', [Reservations::class, 'get']); $app->get('[/]', [Reservations::class, 'get']);
}); });

View File

@ -1,9 +1,7 @@
<?php <?php
//use Incoviba\Controller\Ventas\Cierres; use Incoviba\Controller\Ventas\Cierres;
use Incoviba\Controller\Ventas\Reservations as Cierres;
$app->group('/cierres', function($app) { $app->group('/cierres', function($app) {
$app->get('/project/{project_id}', Cierres::class);
$app->get('[/]', Cierres::class); $app->get('[/]', Cierres::class);
}); });
$app->group('/cierre/{cierre_id}', function($app) { $app->group('/cierre/{cierre_id}', function($app) {

View File

@ -2,5 +2,5 @@
use Incoviba\Controller\Ventas\Precios; use Incoviba\Controller\Ventas\Precios;
$app->group('/precios', function($app) { $app->group('/precios', function($app) {
$app->get('[/{project_id}[/]]', Precios::class); $app->get('[/]', Precios::class);
}); });

View File

@ -24,12 +24,6 @@
rut.replace(/\D/g, '') rut.replace(/\D/g, '')
return rut.replace(/^(\d{1,2})(\d{3})(\d{3})$/, '$1.$2.$3') return rut.replace(/^(\d{1,2})(\d{3})(\d{3})$/, '$1.$2.$3')
} }
static clean(rut) {
if (!(typeof rut === 'string' || rut instanceof String)) {
rut = rut.toString()
}
return rut.replace(/\D/g, '')
}
static validar(rut, digito) { static validar(rut, digito) {
if (!(typeof digito === 'string' || digito instanceof String)) { if (!(typeof digito === 'string' || digito instanceof String)) {
digito = digito.toString() digito = digito.toString()

View File

@ -156,7 +156,7 @@
<script> <script>
const regiones = [ const regiones = [
@foreach ($regiones as $region) @foreach ($regiones as $region)
'<div class="item" data-value="{{$region->id}}">{{$region->numeral}} - {{$region->descripcion}}</div>', '<div class="item" data-value="{{$region->id}}">{{$region->descripcion}}</div>',
@endforeach @endforeach
] ]

View File

@ -54,23 +54,22 @@
} }
$(document).ready(() => { $(document).ready(() => {
const url = '{{$urls->api}}/ventas/pago/{{$venta->resciliacion()->id}}' const url = '{{$urls->api}}/ventas/pago/{{$venta->resciliacion()->id}}'
let old = new Date(Date.parse('{{$venta->resciliacion()?->fecha->format('Y-m-d') ?? $venta->currentEstado()->fecha->format('Y-m-d') ?? $venta->fecha->format('Y-m-d')}}') + 24 * 60 * 60 * 1000) let old = new Date({{$venta->resciliacion()?->fecha->format('Y') ?? date('Y')}},
{{$venta->resciliacion()?->fecha->format('n') ?? date('n')}}-1, {{$venta->resciliacion()?->fecha->format('j') ?? date('j')}})
calendar_date_options['initialDate'] = old calendar_date_options['initialDate'] = old
calendar_date_options['onChange'] = function(date, text, mode) { calendar_date_options['onChange'] = function(date, text, mode) {
if (date.getTime() === old.getTime()) { if (date.getTime() === old.getTime()) {
return return
} }
const body = new FormData() const body = new FormData()
const fecha = new Date(date.getTime()) body.set('fecha', date.toISOString())
fecha.setDate(fecha.getDate() - 1)
body.set('fecha', fecha.toISOString())
$('#loading-spinner-fecha').show() $('#loading-spinner-fecha').show()
APIClient.fetch(url, {method: 'post', body}).then(response => { APIClient.fetch(url, {method: 'post', body}).then(response => {
$('#loading-spinner-fecha').hide() $('#loading-spinner-fecha').hide()
if (!response) { if (!response) {
return return
} }
old = new Date(date.getTime()) old = date
alertResponse('Fecha cambiada correctamente.') alertResponse('Fecha cambiada correctamente.')
}) })
} }

View File

@ -6,26 +6,15 @@
@section('venta_content') @section('venta_content')
<div class="ui list"> <div class="ui list">
@if (isset($venta->formaPago()->pie)) <div class="item">
<div class="item"> <div class="header">Valor Pagado</div>
<div class="header">Valor Pagado</div> <div class="content">
<div class="content"> {{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}} <div class="ui left pointing small label">
<div class="ui left pointing small label"> {{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
</div>
</div> </div>
</div> </div>
@else </div>
<div class="item">
<div class="ui compact warning message">
<div class="content">
<i class="exclamation triangle icon"></i>
No tiene valor pagado
</div>
</div>
</div>
@endif
<div class="item"> <div class="item">
<div class="header"> <div class="header">
Multa Estandar Multa Estandar

View File

@ -24,9 +24,6 @@
<button class="ui tiny green icon button" id="add_button"> <button class="ui tiny green icon button" id="add_button">
<i class="plus icon"></i> <i class="plus icon"></i>
</button> </button>
<button class="ui tiny green icon button" id="import_button">
<i class="upload icon"></i>
</button>
</div> </div>
</div> </div>
</h4> </h4>
@ -34,7 +31,6 @@
<table class="ui table" id="list_data"></table> <table class="ui table" id="list_data"></table>
</div> </div>
</div> </div>
@include('ventas.precios.modal.import')
<div class="ui modal" id="list_modal"> <div class="ui modal" id="list_modal">
<div class="header"> <div class="header">
Actualizar <span id="modal_title"></span> Actualizar <span id="modal_title"></span>
@ -101,8 +97,7 @@
return this.precio / this.superficie return this.precio / this.superficie
} }
draw(formatter) { draw(formatter) {
const dateParts = this.fecha.split('-') const date = new Date(this.fecha)
const date = new Date(dateParts[0], dateParts[1] - 1, dateParts[2])
const dateFormatter = new Intl.DateTimeFormat('es-CL') const dateFormatter = new Intl.DateTimeFormat('es-CL')
return $('<tr></tr>').addClass('unidad').attr('data-linea', this.linea).append( return $('<tr></tr>').addClass('unidad').attr('data-linea', this.linea).append(
$('<td></td>').html(this.nombre) $('<td></td>').html(this.nombre)
@ -322,8 +317,7 @@
buttons: { buttons: {
add: '', add: '',
up: '', up: '',
refresh: '', refresh: ''
import: ''
} }
}, },
data: { data: {
@ -336,11 +330,6 @@
loading: { loading: {
precios: false precios: false
}, },
components: {
modals: {
import: null
}
},
get: function() { get: function() {
return { return {
proyectos: () => { proyectos: () => {
@ -389,24 +378,6 @@
} }
} }
}, },
url() {
return {
proyectos: () => {
const currentUrl = window.location.href
const newUrl = `{{ $urls->base }}/ventas/precios`
if (newUrl !== currentUrl) {
window.history.replaceState(null, null, newUrl)
}
},
precios: proyecto_id => {
const currentUrl = window.location.href
const newUrl = `{{ $urls->base }}/ventas/precios/${proyecto_id}`
if (newUrl !== currentUrl) {
window.history.replaceState(null, null, newUrl)
}
}
}
},
add: function() { add: function() {
return { return {
precio: data => { precio: data => {
@ -429,7 +400,6 @@
draw: function() { draw: function() {
return { return {
proyectos: () => { proyectos: () => {
this.url().proyectos()
const parent = $(this.ids.list) const parent = $(this.ids.list)
const header = parent.find('#list_title') const header = parent.find('#list_title')
const list = parent.find('.list') const list = parent.find('.list')
@ -438,7 +408,6 @@
$(this.ids.buttons.add).hide() $(this.ids.buttons.add).hide()
$(this.ids.buttons.add).attr('data-id', '') $(this.ids.buttons.add).attr('data-id', '')
$(this.ids.buttons.add).attr('data-proyecto', '') $(this.ids.buttons.add).attr('data-proyecto', '')
$(`#${this.ids.buttons.import}`).hide()
header.html('Proyectos') header.html('Proyectos')
table.hide() table.hide()
@ -446,8 +415,7 @@
this.data.proyectos.forEach(proyecto => { this.data.proyectos.forEach(proyecto => {
list.append( list.append(
$('<div></div>').addClass('item proyecto').attr('data-proyecto', proyecto.id) $('<div></div>').addClass('item proyecto').attr('data-proyecto', proyecto.id).html(proyecto.descripcion).css('cursor', 'pointer')
.html(proyecto.descripcion).css('cursor', 'pointer')
) )
}) })
list.show() list.show()
@ -463,7 +431,6 @@
}) })
}, },
precios: () => { precios: () => {
this.url().precios(this.data.id)
const parent = $(this.ids.list) const parent = $(this.ids.list)
const header = parent.find('#list_title') const header = parent.find('#list_title')
const list = parent.find('.list') const list = parent.find('.list')
@ -473,8 +440,6 @@
$(this.ids.buttons.add).attr('data-proyecto', this.data.proyecto) $(this.ids.buttons.add).attr('data-proyecto', this.data.proyecto)
$(this.ids.buttons.add).show() $(this.ids.buttons.add).show()
$(`#${this.ids.buttons.import}`).show()
header.html('Precios de ' + this.data.proyecto) header.html('Precios de ' + this.data.proyecto)
list.hide() list.hide()
table.html('') table.html('')
@ -616,27 +581,18 @@
} }
} }
}, },
import: event => {
event.preventDefault()
precios.components.modals.import.show(this.data.id)
return false
}
} }
}, },
setup: function({list, proyectos, buttons_up, buttons_refresh, buttons_add, buttons_import}) { setup: function({list, proyectos, buttons_up, buttons_refresh, buttons_add}) {
this.ids.list = list this.ids.list = list
this.ids.proyectos = proyectos this.ids.proyectos = proyectos
this.ids.buttons.up = buttons_up this.ids.buttons.up = buttons_up
this.ids.buttons.refresh = buttons_refresh this.ids.buttons.refresh = buttons_refresh
this.ids.buttons.add = buttons_add this.ids.buttons.add = buttons_add
this.ids.buttons.import = buttons_import
$(this.ids.buttons.up).click(this.actions().up) $(this.ids.buttons.up).click(this.actions().up)
$(this.ids.buttons.refresh).click(this.actions().refresh) $(this.ids.buttons.refresh).click(this.actions().refresh)
$(this.ids.buttons.add).click(this.actions().add().list) $(this.ids.buttons.add).click(this.actions().add().list)
document.getElementById(this.ids.buttons.import).addEventListener('click', this.actions().import)
this.components.modals.import = new ImportModal()
this.draw().proyectos() this.draw().proyectos()
} }
@ -718,10 +674,6 @@
$(this.ids.button).click(this.actions().send) $(this.ids.button).click(this.actions().send)
} }
} }
function selectProject(projectId) {
const $project = $(`.item.proyecto[data-proyecto="${projectId}"]`)
$project.click()
}
$(document).ready(() => { $(document).ready(() => {
precios.setup({ precios.setup({
@ -729,8 +681,7 @@
proyectos: '#proyectos', proyectos: '#proyectos',
buttons_up: '#up_button', buttons_up: '#up_button',
buttons_refresh: '#refresh_button', buttons_refresh: '#refresh_button',
buttons_add: '#add_button', buttons_add: '#add_button'
buttons_import: 'import_button'
}) })
list_modal.setup({ list_modal.setup({
modal: '#list_modal', modal: '#list_modal',
@ -741,10 +692,6 @@
fields_valor: '#valor', fields_valor: '#valor',
button: '#send' button: '#send'
}) })
@if (isset($project_id))
selectProject({{$project_id}})
@endif
}) })
</script> </script>
@endpush @endpush

View File

@ -1,120 +0,0 @@
<div class="ui modal" id="import_modal">
<div class="header">
Importar Precios
</div>
<div class="content">
<div class="ui form">
<input type="hidden" id="import_project_id" name="import_project_id" value="" />
<div class="three wide field">
<div class="ui calendar" id="import_date">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha" />
</div>
</div>
</div>
<input class="ui invisible file input" type="file" id="import_file" name="file" />
<label class="ui placeholder segment" for="import_file">
<div class="ui icon header">
<i class="upload icon"></i>
Archivo de Precios
</div>
</label>
</div>
</div>
<div class="actions">
<div class="ui red cancel icon button">
<i class="remove icon"></i>
</div>
<div class="ui green ok icon button">
<i class="checkmark icon"></i>
Importar
</div>
</div>
@push('page_scripts')
<script>
class ImportModal {
ids = {
modal: '',
project: '',
calendar: '',
file: ''
}
components = {
$modal: null,
form: null,
project: null,
$calendar: null,
file: null,
$file: null
}
constructor() {
this.ids.modal = 'import_modal'
this.ids.project = 'import_project_id'
this.ids.calendar = 'import_date'
this.ids.file = 'import_file'
this.setup()
}
show(project_id) {
this.components.project.value = project_id
this.components.$modal.modal('show')
}
dragDrop(event) {
event.preventDefault()
if (event.originalEvent.dataTransfer && event.originalEvent.dataTransfer.files.length > 0) {
this.components.file.files = event.originalEvent.dataTransfer.files
}
}
import() {
const url = '{{ $urls->api }}/ventas/precios/import'
const method = 'post'
const body = new FormData()
body.set('project_id', this.components.project.value)
const date = this.components.$calendar.calendar('get date')
body.set('date', [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-'))
body.set('file', this.components.file.files[0])
APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
if (json.status === true) {
window.location.reload()
return
}
console.debug(json)
})
}
setup() {
this.components.$modal = $(`#${this.ids.modal}`)
this.components.$modal.modal({
onApprove: () => {
this.import()
}
})
this.components.form = this.components.$modal.find('form')
this.components.form.submit(event => {
event.preventDefault()
this.import()
return false
})
this.components.project = document.getElementById(this.ids.project)
this.components.$calendar = $(`#${this.ids.calendar}`)
const cdo = structuredClone(calendar_date_options)
cdo['maxDate'] = new Date()
this.components.$calendar.calendar(cdo)
this.components.file = document.getElementById(this.ids.file)
this.components.$file = $(this.components.file.parentNode.querySelector('label'))
this.components.$file.css('cursor', 'pointer')
this.components.$file.on('dragover', event => {
event.preventDefault()
event.stopPropagation()
})
this.components.$file.on('dragenter', event => {
event.preventDefault()
event.stopPropagation()
})
this.components.$file.on('drop', this.dragDrop.bind(this))
}
}
</script>
@endpush

View File

@ -1,664 +0,0 @@
@extends('layout.base')
@section('page_title')
Cierres - Reservas
@endsection
@section('page_content')
<div class="ui container">
<h2 class="ui header">Cierres - Reservas</h2>
<div class="ui compact segment" id="projects">
<div class="ui header">Proyectos</div>
@if (count($projects) == 0)
<div class="ui message">
No hay proyectos en venta.
</div>
@else
<div class="ui link list">
@foreach ($projects as $project)
<div class="item link" data-id="{{ $project->id }}">
{{ $project->descripcion }}
</div>
@endforeach
</div>
@endif
</div>
<div class="ui two column grid">
<div class="column">
<h3 class="ui header" id="project"></h3>
</div>
<div class="column">
<div class="ui active inline loader" id="loader"></div>
</div>
</div>
<div id="results">
<div class="ui right aligned top attached basic segment" id="controls">
<div class="ui tiny icon buttons">
<button class="ui button" id="up_button">
<i class="up arrow icon"></i>
</button>
<button class="ui button" id="refresh_button">
<i class="refresh icon"></i>
</button>
<button class="ui green icon button" id="add_button">
<i class="plus icon"></i>
</button>
</div>
</div>
<div class="ui top attached tabular menu" id="tabs">
<div class="yellow active item" data-tab="pending">Pendientes</div>
<div class="green item" data-tab="active">Activas</div>
<div class="red item" data-tab="rejected">Rechazadas</div>
</div>
<div class="ui bottom attached tab fitted segment active" data-tab="pending">
<table class="ui yellow striped table" id="pending_reservations">
<thead>
<tr>
<th>Unidades</th>
<th>Cliente</th>
<th>Fecha</th>
<th>Oferta</th>
<th>¿Valida?</th>
<th>Operador</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div class="ui bottom attached tab fitted segment" data-tab="active">
<table class="ui green striped table" id="active_reservations">
<thead>
<tr>
<th>Unidades</th>
<th>Cliente</th>
<th>Fecha</th>
<th>Oferta</th>
<th>Operador</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div class="ui bottom attached tab fitted segment" data-tab="rejected">
<table class="ui red striped table" id="rejected_reservations">
<thead>
<tr>
<th>Unidades</th>
<th>Cliente</th>
<th>Fecha</th>
<th>Oferta</th>
<th>Estado</th>
<th>Operador</th>
<th>Comentarios</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
@include('ventas.reservations.modal.add')
@endsection
@push('page_styles')
<style>
.item.link {
cursor: pointer;
text-decoration: underline;
}
</style>
@endpush
@push('page_scripts')
<script>
class Projects {
display = {
projects: '',
project: ''
}
component_id = ''
component = null
current_project = null;
title_id = ''
title_component = null
constructor({component_id, title_id}) {
this.component_id = component_id
this.component = document.getElementById(this.component_id)
this.display.projects = this.component.style.display
this.title_id = title_id
this.title_component = document.getElementById(this.title_id)
this.display.project = this.title_component.style.display
this.show()
this.watch()
}
select(event) {
event.preventDefault()
const project_id = event.currentTarget.dataset.id
reservations.show.results()
reservations.update.url(project_id)
if (project_id === this.current_project) {
this.hide()
this.title_component.innerHTML = event.currentTarget.innerHTML
reservations.action.reservations()
return
}
this.current_project = project_id
reservations.get.reservations(project_id)
reservations.components.modals.add.load(project_id)
this.hide()
this.title_component.innerHTML = event.currentTarget.innerHTML
}
watch() {
this.component.querySelectorAll('.item.link').forEach(item => {
item.addEventListener('click', this.select.bind(this))
})
}
load(project_id) {
this.component.querySelector(`.item.link[data-id="${project_id}"]`).click()
}
show() {
this.component.style.display = this.display.projects
this.title_component.style.display = 'none'
}
hide() {
this.component.style.display = 'none'
this.title_component.style.display = this.display.project
}
}
class Controls {
display = {
up: '',
reset: '',
}
component_id = ''
component = null
buttons = {
up: null,
reset: null,
add: null
}
constructor({component_id}) {
this.component_id = component_id
this.component = document.getElementById(this.component_id)
const buttons = this.component.querySelectorAll('button')
this.buttons.up = buttons[0]
this.buttons.reset = buttons[1]
this.buttons.add = buttons[2]
this.display.up = buttons[0].style.display
this.display.reset = buttons[1].style.display
this.watch()
this.hide()
}
watch() {
Object.entries(this.buttons).forEach(([key, value]) => {
const name = key.replace('_button', '')
value.addEventListener('click', this.action[name].bind(this))
})
}
hide() {
this.buttons.up.style.display = this.display.up
this.buttons.reset.style.display = this.display.reset
}
show() {
this.buttons.up.style.display = 'none'
this.buttons.reset.style.display = 'none'
}
action = {
reset: event => {
event.preventDefault()
reservations.action.reset(event)
return false
},
up: event => {
event.preventDefault()
reservations.action.up(event)
return false
},
add: event => {
event.preventDefault()
reservations.action.add(event)
return false
}
}
}
class Reservations {
display = {
reservations: '',
}
component_id = ''
component = null
formatters = {
date: null,
ufs: null
}
columnNames = []
reservations = []
constructor({component_id, formatters = {date, ufs}}) {
this.component_id = component_id
this.component = document.getElementById(this.component_id)
this.display.reservations = this.component.style.display
this.formatters = formatters
this.set.columnNames()
this.hide()
}
set = {
reservations: reservations => {
this.reservations = reservations
return this
},
columnNames: () => {
const tds = this.component.querySelector('thead tr').querySelectorAll('th')
this.columnNames = []
tds.forEach(td => {
let name = td.innerHTML.toLowerCase()
if (name === '') {
return
}
if (name.includes('?')) {
name = name.replaceAll(/[¿?]/g, '')
}
this.columnNames.push(name)
})
return this
}
}
columnsData() {
return this.reservations.map(reservation => {
const date = new Date(Date.parse(reservation.date) + 24 * 60 * 60 * 1000)
return {
id: reservation.id,
unidades: reservation.summary,
cliente: reservation.buyer.nombreCompleto,
fecha: this.formatters.date.format(date),
oferta: `${this.formatters.ufs.format(reservation.offer)} UF`,
valida: reservation.valid ? '<span class="ui green text">Si</span>' : '<span class="ui red text">No</span>',
operador: reservation.broker?.name ?? '',
}
})
}
draw() {
if (this.reservations.length === 0) {
this.empty()
return
}
const tbody = this.component.querySelector('tbody')
tbody.innerHTML = ''
this.columnsData().forEach(column => {
const tr = document.createElement('tr')
const contents = []
const id = column.id
this.columnNames.forEach(name => {
contents.push(`<td>${column[name]}</td>`)
})
const actions = this.drawActions(id)
if (actions !== '') {
contents.push(actions)
}
tr.innerHTML = contents.join("\n")
tbody.appendChild(tr)
})
this.show()
this.watch()
}
drawActions(id) {
return `
<td class="right aligned">
<button class="ui green mini icon button approve" data-id="${id}" title="Aprobar">
<i class="check icon"></i>
</button>
<button class="ui red mini icon button reject" data-id="${id}" title="Rechazar">
<i class="trash icon"></i>
</button>
</td>`
}
watch() {
if (Object.keys(this.actions).length === 0) {
return
}
const actionNames = Object.keys(this.actions)
const tbody = this.component.querySelector('tbody')
const trs = tbody.querySelectorAll('tr')
trs.forEach(tr => {
actionNames.forEach(actionName => {
const button = tr.querySelector(`button.${actionName}`)
if (!button) {
return
}
button.addEventListener('click', this.actions[actionName].bind(this))
})
})
}
empty() {
const tbody = this.component.querySelector('tbody')
tbody.innerHTML = ''
const col_span = this.columnNames.length + 1
const tr = document.createElement('tr')
tr.innerHTML = `<td colspan="${col_span}">No hay cierres</td>`
tbody.appendChild(tr)
this.show()
}
show() {
this.component.style.display = this.display.reservations
}
hide() {
this.component.style.display = 'none'
}
send = {
get(url) {
return APIClient.fetch(url).then(response => response.json()).then(json => {
if (json.success) {
window.location.reload()
}
})
},
post(url, body) {
const method = 'post'
return APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
if (json.success) {
window.location.reload()
}
})
},
delete(url) {
const method = 'delete'
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
if (json.success) {
window.location.reload()
}
})
}
}
actions = {}
}
class ActiveReservations extends Reservations {
constructor({component_id, formatters = {date, ufs}}) {
super({component_id, formatters})
}
columnsData() {
const data = super.columnsData();
return data.map(row => {
delete (row['valida'])
return row
})
}
drawActions(id) {
return `
<td class="right aligned">
<button class="ui green mini icon button edit" data-id="${id}" title="Promesar">
<i class="right chevron icon"></i>
</button>
<button class="ui red mini icon button remove" data-id="${id}" title="Abandonar">
<i class="trash icon"></i>
</button>
</td>`
}
actions = {
edit: event => {
event.preventDefault()
const id = event.currentTarget.dataset.id
reservations.components.modals.edit.load(id)
return false
},
remove: event => {
event.preventDefault()
const id = event.currentTarget.dataset.id
const url = `{{ $urls->api }}/ventas/reservation/${id}/remove`
this.send.delete(url)
return false
}
}
}
class PendingReservations extends Reservations {
constructor({component_id, formatters = {date, ufs}}) {
super({component_id, formatters})
}
actions = {
approve: event => {
event.preventDefault()
const id = event.currentTarget.dataset.id
const url = `{{ $urls->api }}/ventas/reservation/${id}/approve`
this.send.get(url)
return false
},
reject: event => {
event.preventDefault()
const id = event.currentTarget.dataset.id
const url = `{{ $urls->api }}/ventas/reservation/${id}/reject`
this.send.get(url)
return false
}
}
}
class RejectedReservations extends Reservations {
constructor({component_id, formatters = {date, ufs}}) {
super({component_id, formatters})
}
columnsData() {
const data = super.columnsData()
return this.reservations.map((reservation, idx) => {
data[idx]['estado'] = reservation.state.charAt(0).toUpperCase() + reservation.state.slice(1)
data[idx]['comentarios'] = reservation.comments?.join('<br />\n') ?? ''
return data[idx]
})
}
drawActions(id) {
return ''
}
watch() {}
}
const reservations = {
components: {
projects: null,
loader: null,
results: null,
controls: null,
reservations: {
active: null,
pending: null,
rejected: null
},
modals: {
add: null
}
},
display: {
loader: '',
results: '',
},
get: {
send: (project_id, url_segment, component) => {
const url = `/api/ventas/reservations/project/${project_id}/${url_segment}`
return APIClient.fetch(url).then(response => response.json()).then(json => {
if (json.reservations.length > 0) {
component.set.reservations(json.reservations)
}
component.draw()
})
},
active: project_id => {
return reservations.get.send(project_id, 'active', reservations.components.reservations.active)
},
pending: project_id => {
return reservations.get.send(project_id, 'pending', reservations.components.reservations.pending)
},
rejected: project_id => {
return reservations.get.send(project_id, 'rejected', reservations.components.reservations.rejected)
},
reservations: project_id => {
reservations.loading.show()
const promises = []
promises.push(reservations.get.active(project_id))
promises.push(reservations.get.pending(project_id))
promises.push(reservations.get.rejected(project_id))
return Promise.any(promises).then(() => {
reservations.loading.hide()
})
},
pathname: project_id => {
const current_url = new URL(window.location.href)
if (project_id === null) {
if (current_url.pathname.includes('project')) {
return current_url.pathname.replace(/\/project\/\d+/, '')
}
return current_url.pathname
}
if (current_url.pathname.includes('project')) {
return current_url.pathname.replace(/project\/\d+/, `project/${project_id}`)
}
return `${current_url.pathname}/project/${project_id}`
}
},
loading: {
show: () => {
reservations.components.loader.style.display = reservations.display.loader
},
hide: () => {
reservations.components.loader.style.display = 'none'
}
},
update: {
url: project_id => {
window.history.pushState(null, '', reservations.get.pathname(project_id))
}
},
action: {
reset: event => {
event.preventDefault()
reservations.components.projects.current_project = null
Object.entries(reservations.components.reservations).forEach(([key, value]) => {
reservations.components.reservations[key].reservations = []
reservations.components.reservations[key].hide()
})
reservations.show.projects()
reservations.update.url(null)
return false
},
up: event => {
event.preventDefault()
Object.values(reservations.components.reservations).forEach(reservations => reservations.hide())
reservations.show.projects()
reservations.update.url(null)
return false
},
add: event => {
event.preventDefault()
reservations.components.modals.add.show()
return false
},
reservations: () => {
Object.values(reservations.components.reservations).forEach(reservations => {
reservations.draw()
})
}
},
show: {
projects: () => {
reservations.components.projects.show()
reservations.components.results.style.display = 'none'
},
results: () => {
reservations.components.projects.hide()
reservations.components.results.style.display = reservations.display.results
Object.values(reservations.components.reservations).forEach(reservations => reservations.draw())
}
},
setup(configuration) {
const formatters = {
date: new Intl.DateTimeFormat('es-CL', {year: 'numeric', month: 'long', day: 'numeric'}),
ufs: new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
}
this.components.loader = document.getElementById(configuration.ids.loader)
this.components.projects = new Projects({
component_id: configuration.ids.projects,
title_id: configuration.ids.project
})
this.components.controls = new Controls({component_id: configuration.ids.controls})
this.components.reservations.active = new ActiveReservations({
component_id: configuration.ids.active,
formatters
})
this.components.reservations.pending = new PendingReservations({
component_id: configuration.ids.pending,
formatters
})
this.components.reservations.rejected = new RejectedReservations({
component_id: configuration.ids.rejected,
formatters
})
this.display.loader = this.components.loader.style.display
this.loading.hide()
$(`#${configuration.ids.tabs} .item`).tab()
this.components.results = document.getElementById(configuration.ids.results)
this.display.results = this.components.results.style.display
this.show.projects()
this.components.modals.add = new AddReservationModal(configuration.ids.projects)
const project_id = {{ $project_id ?? 'null' }};
if (project_id !== null) {
reservations.components.projects.load(project_id)
}
}
}
$(document).ready(() => {
reservations.setup({
ids: {
projects: 'projects',
project: 'project',
results: 'results',
loader: 'loader',
controls: 'controls',
tabs: 'tabs',
active: 'active_reservations',
pending: 'pending_reservations',
rejected: 'rejected_reservations',
}
})
})
</script>
@endpush

View File

@ -1,758 +0,0 @@
<div class="ui modal" id="add_reservation_modal">
<div class="header">
Agregar Cierre
</div>
<div class="content">
<form class="ui form" id="add_reservation_form">
<input type="hidden" name="add_project_id" />
<div class="three wide required field">
<label>Fecha</label>
<div class="ui calendar" id="add_date">
<div class="ui icon input">
<i class="calendar icon"></i>
<input type="text" name="add_date" />
</div>
</div>
</div>
<div class="fields">
<div class="three wide required field">
<label>RUT</label>
<div class="ui right labeled input" id="add_rut">
<input type="text" name="add_buyer_rut" placeholder="RUT" />
<div class="ui basic label">-<span id="add_digit"></span></div>
</div>
</div>
<div class="field">
<label></label>
<div class="ui inline loader" id="add_rut_loader"></div>
</div>
</div>
<div class="fields">
<div class="three wide required field">
<label>Nombre</label>
<input type="text" name="add_buyer_name" placeholder="Nombre" />
</div>
<div class="six wide required field">
<label>Apellidos</label>
<input type="text" name="add_buyer_last_name" placeholder="Apellido Paterno" />
</div>
<div class="six wide field">
<label></label>
<input type="text" name="add_buyer_last_name2" placeholder="Apellido Materno" />
</div>
</div>
<div class="fields">
<div class="three wide field">
<label>Dirección</label>
<input type="text" name="add_buyer_address_street" placeholder="Calle" />
</div>
<div class="field">
<label></label>
<input type="text" name="add_buyer_address_number" placeholder="" />
</div>
<div class="three wide field">
<label></label>
<input type="text" name="add_buyer_address_extra" placeholder="Otros Detalles" />
</div>
</div>
<div class="fields">
<div class="three wide field">
<label>Comuna</label>
<div class="ui search selection dropdown" id="add_comuna">
<input type="hidden" name="comuna" />
<i class="dropdown icon"></i>
<div class="default text">Comuna</div>
<div class="menu"></div>
</div>
</div>
<div class="seven wide field">
<label>Región</label>
<div class="ui search selection dropdown" id="add_region">
<input type="hidden" name="region" />
<i class="dropdown icon"></i>
<div class="default text">Región</div>
<div class="menu">
@foreach($regions as $region)
<div class="item" data-value="{{$region->id}}">{{$region->numeral}} - {{$region->descripcion}}</div>
@endforeach
</div>
</div>
</div>
</div>
<div class="fields">
<div class="field">
<label>Telefono</label>
<input type="text" name="add_buyer_phone" placeholder="Telefono" />
</div>
<div class="field">
<label>Correo</label>
<div class="ui labeled input">
<input type="text" name="add_buyer_email_name" placeholder="Correo" />
<div class="ui basic label">@</div>
<input type="text" name="add_buyer_email_domain" placeholder="Dominio" />
</div>
</div>
</div>
<div class="fields">
<div class="field">
<label>Estado Civil</label>
<input type="text" name="add_buyer_marital_status" placeholder="Estado Civil" />
</div>
<div class="field">
<label>Profesión</label>
<input type="text" name="add_buyer_profession" placeholder="Profesión" />
</div>
<div class="field">
<label>Fecha de Nacimiento</label>
<div class="ui calendar" id="add_birthdate">
<div class="ui icon input">
<i class="calendar icon"></i>
<input type="text" name="birthdate" />
</div>
</div>
</div>
</div>
<div class="six wide field">
<label>Operador *</label>
<div class="ui clearable search selection dropdown" id="add_broker">
<input type="hidden" name="add_broker" />
<i class="dropdown icon"></i>
<div class="default text">Operador</div>
<div class="menu"></div>
</div>
</div>
<div class="field">
<label>Agregar Promoción</label>
<button type="button" class="ui icon button" id="add_promotion">
<i class="plus icon"></i>
</button>
</div>
<div id="add_promotions"></div>
<h4 class="ui dividing header">Unidades <span id="add_project_name"></span></h4>
<div class="fields" id="add_unit_buttons"></div>
<div id="add_units"></div>
</form>
</div>
<div class="actions">
<div class="ui cancel button">
Cancelar
</div>
<div class="ui green ok button">
Agregar
</div>
</div>
</div>
@include('layout.body.scripts.rut')
@push('page_scripts')
<script>
class AddModalPromotions {
ids = {
button: '',
elements: ''
}
data = {
promotions: []
}
components = {
button: null,
promotions: null,
}
display = {
button: ''
}
constructor() {
this.ids = {
button: 'add_promotion',
elements: 'add_promotions'
}
this.setup()
}
add() {
const idx = Math.max(this.data.promotions.length, 0, Math.max(...this.data.promotions) + 1)
this.data.promotions.push(idx)
this.draw.promotions()
}
reset() {
this.data.promotions = []
this.draw.promotions()
}
remove(idx) {
this.data.promotions = this.data.promotions.filter(promotion => promotion !== idx)
this.draw.promotions()
}
draw = {
promotion: idx => {
const promotions = this.data.promotions.map(promotion => {
return `<div class="item" data-value="${promotion.id}">${promotion.name}</div>`
})
return [
`<div class="fields promotion" data-id="${idx}">`,
'<div class="three wide field">',
'<label>Promoción</label>',
`<div class="ui search selection dropdown">`,
'<input type="hidden" name="add_promotions[]" />',
'<i class="dropdown icon"></i>',
'<div class="default text">Promoción</div>',
`<div class="menu">${promotions.join('')}</div>`,
'</div>',
'</div>',
'<div class="two wide field">',
'<label></label>',
`<button class="ui red tiny icon button remove_promotion" type="button" data-id="${idx}"><i class="trash icon"></i></button>`,
'</div>',
'</div>'
].join('')
},
promotions: () => {
if (this.data.promotions.length === 0) {
this.components.button.parentElement.style.display = 'none'
this.components.promotions.innerHTML = ''
return
}
this.components.button.parentElement.style.display = this.display.button
this.components.promotions.innerHTML = this.data.promotions.map((promotion, idx) => {
return this.draw.promotion(idx)
}).join('')
this.components.promotions.querySelectorAll('.dropdown').forEach(dropdown => {
$(dropdown).dropdown()
})
this.components.promotions.querySelectorAll('.remove_promotion').forEach(button => {
button.addEventListener('click', () => {
const idx = Number(button.dataset.id)
this.remove(idx)
})
})
}
}
setup() {
this.components.button = document.getElementById(this.ids.button)
this.components.promotions = document.getElementById(this.ids.elements)
this.components.button.addEventListener('click', () => {
this.add()
})
this.display.button = this.components.button.parentElement.style.display
this.draw.promotions()
}
}
class AddModalUnits {
ids = {
buttons_holder: '',
units: ''
}
data = {
button_map: {},
types: {},
units: [],
}
components = {
buttons_holder: null,
units: null,
}
constructor() {
this.ids = {
buttons_holder: 'add_unit_buttons',
units: 'add_units'
}
this.data.button_map = {
'departamento': 'building',
'estacionamiento': 'car',
'bodega': 'warehouse',
'terraza': 'vector square'
}
this.setup()
}
draw = {
button: type => {
return [
'<div class="field">',
`<button class="ui icon button" type="button" data-type="${type}" title="${type.charAt(0).toUpperCase() + type.slice(1)}">`,
'<i class="plus icon"></i>',
`<i class="${this.data.button_map[type]} icon"></i>`,
'</button>',
'</div>'
].join('')
},
buttons: () => {
this.components.buttons_holder.innerHTML = Object.keys(this.data.types).map(type => {
return this.draw.button(type)
}).join('')
this.components.buttons_holder.querySelectorAll('.button').forEach(button => {
button.addEventListener('click', () => {
const type = button.dataset.type
this.add(type)
})
})
},
units: () => {
if (this.data.units.length === 0) {
this.components.units.innerHTML = ''
return
}
this.components.units.innerHTML = this.data.units.map(unit => {
return [
'<div class="fields">',
'<div class="four wide field">',
`<label>${unit.type.charAt(0).toUpperCase() + unit.type.slice(1)}</label>`,
`<div class="ui search selection dropdown">`,
'<input type="hidden" name="add_units[]" />',
'<i class="dropdown icon"></i>',
`<div class="default text">${unit.type.charAt(0).toUpperCase() + unit.type.slice(1)}</div>`,
'<div class="menu">',
this.data.types[unit.type].map(unit => {
return `<div class="item" data-value="${unit.value}">${unit.name}</div>`
}).join(''),
'</div>',
'</div>',
'</div>',
'<div class="three wide field">',
'<label>Valor</label>',
'<div class="ui right labeled input">',
'<input type="number" name="add_units_value[]" placeholder="Valor" />',
'<div class="ui basic label">UF</div>',
'</div>',
'</div>',
'<div class="field">',
'<label></label>',
`<button class="ui red tiny icon button remove_unit" type="button" data-id="${unit.idx}"><i class="trash icon"></i></button>`,
'</div>',
'</div>',
].join('')
}).join('')
this.components.units.querySelectorAll('.dropdown').forEach(dropdown => {
$(dropdown).dropdown()
})
this.components.units.querySelectorAll('.remove_unit').forEach(button => {
button.addEventListener('click', () => {
const idx = Number(button.dataset.id)
this.remove(idx)
})
})
}
}
reset() {
this.data.units = []
this.draw.units()
}
add(type) {
const idx = Math.max(this.data.units.length, 0, Math.max(...this.data.units.map(unit => unit.idx)) + 1)
this.data.units.push({idx, type})
this.draw.units()
}
remove(idx) {
this.data.units = this.data.units.filter(unit => unit.idx !== idx)
this.draw.units()
}
setup() {
this.components.buttons_holder = document.getElementById(this.ids.buttons_holder)
this.components.units = document.getElementById(this.ids.units)
this.draw.buttons()
}
}
class AddReservationModal {
ids = {
modal: '',
form: '',
date: '',
rut: '',
digit: '',
birthdate: '',
comuna: '',
region: '',
broker: '',
promotion_button: '',
promotions: '',
projects: '',
project_name: '',
unit_buttons: '',
units: ''
}
components = {
$modal: null,
form: null,
$date: null,
$rut: null,
rut: null,
digit: null,
$birthdate: null,
$comuna: null,
$region: null,
$broker: null,
promotion_button: null,
promotions: null,
projects: null,
project_name: null,
unit_buttons: null,
units: null,
$loader: null
}
data = {
current_project: null,
comunas: {},
brokers: {},
promotions: {},
unit_buttons: [],
units: {},
added_units: {},
current_user: null
}
maps = {
unit_types: {
departamento: 'building',
estacionamiento: 'car',
bodega: 'warehouse',
terraza: 'tree',
}
}
constructor(projects_id) {
this.ids = {
modal: 'add_reservation_modal',
form: 'add_reservation_form',
date: 'add_date',
rut: 'add_rut',
digit: 'add_digit',
birthdate: 'add_birthdate',
comuna: 'add_comuna',
region: 'add_region',
broker: 'add_broker',
promotion_button: 'add_promotion',
promotions: 'add_promotions',
projects: projects_id,
project_name: 'add_project_name',
unit_buttons: 'add_unit_buttons',
units: 'add_units',
loader: 'add_rut_loader'
}
this.setup()
}
load(project_id) {
this.reset()
this.data.current_project = project_id
this.components.project_name.textContent = this.components.projects.querySelector(`.item[data-id="${project_id}"]`).textContent
this.components.form.querySelector('input[name="add_project_id"]').value = project_id
this.get.brokers(project_id)
this.get.promotions(project_id).then(promotions => {
this.components.promotions.data.promotions = promotions
this.components.promotions.draw.promotions()
})
this.get.units(project_id).then(units => {
this.components.units.data.types = units
this.components.units.draw.buttons()
})
}
reset() {
this.components.form.reset()
this.components.promotions.reset()
this.components.units.reset()
}
add() {
const url = '/api/ventas/reservation/add'
const form = document.getElementById(this.ids.form)
const body = new FormData(form)
const date = this.components.$date.calendar('get date')
body.set('add_date', [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-'))
body.set('add_buyer_rut', Rut.clean(this.components.rut.querySelector('input').value))
body.set('add_buyer_digit', this.components.digit.textContent)
body.set('add_buyer_address_comuna_id', this.components.$comuna.dropdown('get value'))
body.set('add_broker_rut', Rut.clean(this.components.$broker.dropdown('get value')))
body.set('add_buyer_email', form.querySelector("input[name='add_buyer_email_name']").value + '@' + form.querySelector("input[name='add_buyer_email_domain']").value)
const birthdate = this.components.$birthdate.calendar('get date')
body.set('add_buyer_birthdate', [birthdate.getFullYear(), birthdate.getMonth() + 1, birthdate.getDate()].join('-'))
body.delete('comuna')
body.delete('region')
body.delete('broker')
body.delete('add_broker')
body.delete('birthdate')
body.delete('add_buyer_email_name')
body.delete('add_buyer_email_domain')
const method = 'post'
return APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
if (json.success) {
window.location.reload()
}
})
}
get = {
comunas: region_id => {
if (region_id in this.data.comunas) {
this.components.$comuna.dropdown('change values', this.data.comunas[region_id])
if (this.data.current_user !== null && this.data.current_user?.direccion?.comuna !== null) {
this.components.$comuna.dropdown('set selected', this.data.current_user.direccion.comuna.id)
}
return
}
const uri = `/api/region/${region_id}/comunas`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
if (json.comunas.length === 0) {
return
}
this.data.comunas[region_id] = json.comunas.map(comuna => {
return {
text: comuna.descripcion,
name: comuna.descripcion,
value: comuna.id
}
})
this.components.$comuna.dropdown('change values', this.data.comunas[region_id])
if (this.data.current_user !== null && this.data.current_user?.direccion?.comuna !== null) {
this.components.$comuna.dropdown('set selected', this.data.current_user.direccion.comuna.id)
}
})
},
brokers: project_id => {
if (project_id in this.data.brokers) {
return new Promise((resolve, reject) => {
resolve(this.data.brokers[project_id])
})
}
const uri = `/api/proyecto/${project_id}/brokers`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
if (json.contracts.length === 0) {
return
}
const formatter = new Intl.NumberFormat('es-CL', { style: 'percent', minimumFractionDigits: 2 })
this.data.brokers[project_id] = json.contracts.map(contract => {
return {
id: contract.id,
broker_rut: contract.broker_rut,
commission: formatter.format(contract.commission),
name: '',
text: '',
}
})
const promises = []
json.contracts.forEach(contract => {
promises.push(this.get.broker(contract.broker_rut))
})
return Promise.all(promises).then(data => {
data.forEach(broker => {
if (!('rut' in broker)) {
return
}
const idx = this.data.brokers[project_id].findIndex(contract => contract.broker_rut === broker.rut)
this.data.brokers[project_id][idx].name = this.data.brokers[project_id][idx].text = `${broker.name} - ${this.data.brokers[project_id][idx].commission}`
})
this.fill.brokers()
})
})
},
broker: (broker_rut) => {
const uri = `/api/proyectos/broker/${broker_rut}`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
if (!('broker' in json)) {
return []
}
return json.broker
})
},
promotions: project_id => {
if (project_id in this.data.promotions) {
return new Promise((resolve, reject) => {
resolve(this.data.promotions[project_id])
})
}
const uri = `/api/proyecto/${project_id}/promotions`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
if (json.promotions.length === 0) {
return this.data.promotions[project_id] = []
}
return this.data.promotions[project_id] = json.promotions.map(promotion => {
return {
text: promotion.name,
name: promotion.name,
value: promotion.id
}
})
})
},
units: project_id => {
if (project_id in this.data.units) {
return new Promise((resolve, reject) => {
resolve(this.data.units[project_id])
})
}
const uri = `/api/proyecto/${project_id}/unidades/disponibles`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
if (json.unidades.length === 0) {
this.data.units[project_id] = {}
return this.data.units[project_id]
}
if (!(project_id in this.data.units)) {
this.data.units[project_id] = {}
}
json.unidades.forEach(unit => {
const type = unit.proyecto_tipo_unidad.tipo_unidad.descripcion
if (!(type in this.data.units[project_id])) {
this.data.units[project_id][type] = []
}
this.data.units[project_id][type].push({
text: unit.descripcion,
name: unit.descripcion,
value: unit.id
})
})
Object.entries(this.data.units[project_id]).forEach(([type, units]) => {
units.sort((a, b) => {
return parseInt(a.text) - parseInt(b.text)
})
this.data.units[project_id][type] = units
})
return this.data.units[project_id]
})
},
user: rut => {
if (this.data.current_user !== null && this.data.current_user?.rut === rut) {
return this.data.current_user
}
this.loader.show()
const uri = `/api/persona/${rut}`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
this.loader.hide()
if (!json.success) {
return
}
this.data.current_user = json.persona
return json.persona
})
}
}
fill = {
user: user => {
const form = this.components.form
form.querySelector('input[name="add_buyer_name"]').value = user.nombres || ''
form.querySelector('input[name="add_buyer_last_name"]').value = user.apellidoPaterno || ''
form.querySelector('input[name="add_buyer_last_name2"]').value = user.apellidoMaterno || ''
form.querySelector('input[name="add_buyer_address_street"]').value = user.datos?.direccion?.calle || ''
form.querySelector('input[name="add_buyer_address_number"]').value = user.datos?.direccion?.numero || ''
form.querySelector('input[name="add_buyer_address_extra"]').value = user.datos?.direccion?.extra || ''
if (parseInt(this.components.$region.dropdown('get value')) !== user.datos?.direccion?.comuna?.provincia?.region?.id) {
this.components.$region.dropdown('set selected', user.datos?.direccion?.comuna?.provincia?.region?.id)
} else {
this.components.$comuna.dropdown('set selected', user.datos?.direccion?.comuna?.id)
}
form.querySelector('input[name="add_buyer_phone"]').value = user.datos?.telefono || ''
const email_parts = user.datos?.email?.split('@') || []
form.querySelector('input[name="add_buyer_email_name"]').value = email_parts[0] || ''
form.querySelector('input[name="add_buyer_email_domain"]').value = email_parts[1] || ''
if (user.datos !== null && 'estadoCivil' in user.datos) {
form.querySelector('input[name="add_buyer_marital_status"]').value = user.datos?.estadoCivil.charAt(0).toUpperCase() + user.datos?.estadoCivil.slice(1)
} else {
form.querySelector('input[name="add_buyer_marital_status"]').value = ''
}
if (user.datos !== null &&'ocupacion' in user.datos) {
form.querySelector('input[name="add_buyer_profession"]').value = user.datos?.ocupacion.charAt(0).toUpperCase() + user.datos?.ocupacion.slice(1).toLowerCase()
} else {
form.querySelector('input[name="add_buyer_profession"]').value = ''
}
if (user.datos !== null &&'fechaNacimiento' in user.datos) {
this.components.$birthdate.calendar('set date', user.datos?.fechaNacimiento)
}
},
brokers: () => {
this.components.$broker.dropdown('change values', this.data.brokers[this.data.current_project])
},
units: () => {
const buttons = []
Object.entries(this.maps.unit_types).forEach(([type, map]) => {
if (!(type in this.data.units[this.data.current_project])) {
return
}
buttons.push(`<div class="field"><div class="ui icon button" data-type="${type}" title="${type.charAt(0).toUpperCase() + type.slice(1)}"><i class="plus icon"></i><i class="${map} icon"></i></div></div>`)
})
this.components.unit_buttons.innerHTML = buttons.join('')
this.components.unit_buttons.querySelectorAll('.ui.icon.button').forEach(button => {
button.addEventListener('click', () => {
this.units.add(button.dataset.type)
})
})
}
}
watch = {
region: (value, text, $choice) => {
this.get.comunas(value)
},
}
loader = {
show: () => {
this.components.$loader.show()
},
hide: () => {
this.components.$loader.hide()
}
}
show() {
this.reset()
this.components.$modal.modal('show')
}
setup() {
this.components.$modal = $(`#${this.ids.modal}`)
this.components.form = document.getElementById(this.ids.form)
this.components.$date = $(`#${this.ids.date}`)
this.components.rut = document.getElementById(this.ids.rut)
this.components.digit = document.getElementById(this.ids.digit)
this.components.$birthdate = $(`#${this.ids.birthdate}`)
this.components.$comuna = $(`#${this.ids.comuna}`)
this.components.$region = $(`#${this.ids.region}`)
this.components.$broker = $(`#${this.ids.broker}`)
this.components.promotions = new AddModalPromotions()
this.components.projects = document.getElementById(this.ids.projects)
this.components.project_name = document.getElementById(this.ids.project_name)
this.components.units = new AddModalUnits()
this.components.$modal.modal({
onApprove: () => {
this.add()
}
})
this.components.form.addEventListener('submit', event => {
event.preventDefault()
this.add()
return false
})
const cdo = structuredClone(calendar_date_options)
cdo['initialDate'] = new Date()
cdo['maxDate'] = new Date()
this.components.$date.calendar(cdo)
const rutInput = this.components.rut.querySelector('input')
rutInput.addEventListener('input', event => {
const value = event.currentTarget.value.replace(/\D/g, '')
if (value.length <= 3) {
return
}
this.components.digit.textContent = Rut.digitoVerificador(value)
})
rutInput.addEventListener('blur', event => {
const value = event.currentTarget.value.replace(/\D/g, '')
if (value.length <= 3) {
return
}
event.currentTarget.value = Rut.format(value)
this.get.user(value).then(user => {
this.fill.user(user)
})
})
const cdo2 = structuredClone(cdo)
cdo2['initialDate'].setFullYear(cdo2['initialDate'].getFullYear() - 18)
cdo2['maxDate'].setFullYear(cdo2['maxDate'].getFullYear() - 18)
this.components.$birthdate.calendar(cdo2)
this.components.$region.dropdown({
fireOnInit: true,
onChange: this.watch.region
})
this.components.$region.dropdown('set selected', 13)
this.components.$comuna.dropdown()
this.components.$broker.dropdown()
this.components.$loader = $(`#${this.ids.loader}`)
}
}
</script>
@endpush

View File

@ -116,18 +116,7 @@ return [
->registerSub($container->get(Incoviba\Service\Contabilidad\Cartola\BCI\Mes::class)); ->registerSub($container->get(Incoviba\Service\Contabilidad\Cartola\BCI\Mes::class));
}, },
'TokuClient' => function(ContainerInterface $container) { 'TokuClient' => function(ContainerInterface $container) {
$logger = $container->get('externalLogger');
$stack = GuzzleHttp\HandlerStack::create();
$stack->push(GuzzleHttp\Middleware::mapRequest(function(Psr\Http\Message\RequestInterface $request) use ($logger) {
$logger->info('Toku Request', [
'method' => $request->getMethod(),
'uri' => (string) $request->getUri(),
'headers' => $request->getHeaders(),
'body' => $request->getBody()->getContents(),
]);
}));
return new GuzzleHttp\Client([ return new GuzzleHttp\Client([
'handler' => $stack,
'base_uri' => $container->get('TOKU_URL'), 'base_uri' => $container->get('TOKU_URL'),
'headers' => [ 'headers' => [
'x-api-key' => $container->get('TOKU_TOKEN'), 'x-api-key' => $container->get('TOKU_TOKEN'),
@ -173,16 +162,6 @@ return [
->register('subscription', $container->get(Incoviba\Service\Venta\MediosPago\Toku\Subscription::class)) ->register('subscription', $container->get(Incoviba\Service\Venta\MediosPago\Toku\Subscription::class))
->register('invoice', $container->get(Incoviba\Service\Venta\MediosPago\Toku\Invoice::class)); ->register('invoice', $container->get(Incoviba\Service\Venta\MediosPago\Toku\Invoice::class));
}, },
Pheanstalk\Pheanstalk::class => function(ContainerInterface $container) {
return Pheanstalk\Pheanstalk::create(
$container->get('BEANSTALKD_HOST'),
$container->has('BEANSTALKD_PORT') ? $container->get('BEANSTALKD_PORT') : 11300
);
},
Incoviba\Service\MQTT::class => function(ContainerInterface $container) {
return new Incoviba\Service\MQTT()
->register('default', $container->get(Incoviba\Service\MQTT\Pheanstalk::class));
},
Incoviba\Service\Queue::class => function(ContainerInterface $container) { Incoviba\Service\Queue::class => function(ContainerInterface $container) {
return new Incoviba\Service\Queue( return new Incoviba\Service\Queue(
$container->get(Psr\Log\LoggerInterface::class), $container->get(Psr\Log\LoggerInterface::class),
@ -224,9 +203,5 @@ return [
$container->get(Incoviba\Service\Queue::class) $container->get(Incoviba\Service\Queue::class)
) )
->register($container->get(Incoviba\Service\Venta\MediosPago\Toku::class)); ->register($container->get(Incoviba\Service\Venta\MediosPago\Toku::class));
},
Incoviba\Service\FileUpload::class => function(ContainerInterface $container) {
return new Incoviba\Service\FileUpload($container->get(Psr\Log\LoggerInterface::class))
->register($container->get(Incoviba\Service\FileUpload\ExcelBase::class));
} }
]; ];

View File

@ -1,34 +0,0 @@
<?php
namespace Incoviba\Controller\API;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Exception\ServiceAction;
use Incoviba\Repository;
use Incoviba\Service;
class Personas extends Ideal\Controller
{
use withJson;
public function get(ServerRequestInterface $request, ResponseInterface $response,
Service\Persona $personaService, int $rut): ResponseInterface
{
$output = [
'rut' => $rut,
'persona' => null,
'success' => false
];
try {
$persona = $personaService->getById($rut);
$output['persona'] = $persona;
$output['success'] = true;
} catch (ServiceAction\Read $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
}
return $this->withJson($response, $output);
}
}

View File

@ -187,18 +187,5 @@ class Proyectos
} }
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function promotions(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Promotion $promotionService, int $proyecto_id): ResponseInterface
{
$output = [
'project_id' => $proyecto_id,
'promotions' => []
];
try {
$output['promotions'] = $promotionService->getByProject($proyecto_id);
} catch (Read $exception) {
return $this->withError($response, $exception);
}
return $this->withJson($response, $output);
}
} }

View File

@ -22,4 +22,20 @@ class Queues extends Ideal\Controller
} }
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function jobs(ServerRequestInterface $request, ResponseInterface $response,
Service\Queue $queueService): ResponseInterface
{
$output = [
'jobs' => array_column($queueService->getPendingJobs(), 'id')
];
return $this->withJson($response, $output);
}
public function run(ServerRequestInterface $request, ResponseInterface $response, Service\Queue $queueService,
int $job_id): ResponseInterface
{
if ($queueService->runJob($job_id, $request)) {
return $response->withStatus(200);
}
return $response->withStatus(422);
}
} }

View File

@ -146,25 +146,4 @@ class Toku extends Controller
} }
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function update(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\MediosPago\Toku $tokuService, ?string $type = null): ResponseInterface
{
$body = $request->getBody()->getContents();
$input = json_decode($body, true);
$output = [
'type' => $type,
'input' => $input,
'output' => [],
'success' => false
];
try {
$output['output'] = $tokuService->update($input, $type);
$output['success'] = true;
} catch (Exception $exception) {
$this->logger->error($exception);
}
return $this->withJson($response, $output);
}
} }

View File

@ -1,16 +1,13 @@
<?php <?php
namespace Incoviba\Controller\API\Ventas; namespace Incoviba\Controller\API\Ventas;
use DateTime;
use Exception;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\{EmptyRedis,EmptyResult}; use Incoviba\Common\Implement\Exception\EmptyRedis;
use Psr\Log\LoggerInterface; use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\API\{withJson,emptyBody}; use Incoviba\Controller\API\{withJson,emptyBody};
use Incoviba\Controller\withRedis;
use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Service; use Incoviba\Service;
use Incoviba\Controller\withRedis;
class Precios class Precios
{ {
@ -54,29 +51,4 @@ class Precios
} }
} }
} }
public function import(ServerRequestInterface $request, ResponseInterface $response,
LoggerInterface $logger,
Service\Venta\Precio $precioService): ResponseInterface
{
$body = $request->getParsedBody();
$projectId = $body['project_id'];
$date = $body['date'];
$file = $request->getUploadedFiles()['file'];
$output = [
'input' => $body,
'total' => 0,
'precios' => [],
'status' => false
];
$date = DateTime::createFromFormat('Y-m-d', $date);
try {
$output['precios'] = $precioService->import($projectId, $date, $file);
$output['total'] = count($output['precios']);
$output['status'] = true;
} catch (Create | Exception $exception) {
$logger->warning($exception);
}
return $this->withJson($response, $output);
}
} }

View File

@ -11,8 +11,7 @@ class Reservations
{ {
use withJson; use withJson;
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService): ResponseInterface
Service\Venta\Reservation $reservationService): ResponseInterface
{ {
$reservations = []; $reservations = [];
try { try {
@ -23,18 +22,6 @@ class Reservations
return $this->withJson($response, compact('reservations')); return $this->withJson($response, compact('reservations'));
} }
public function getByProject(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Reservation $reservationService, int $project_id): ResponseInterface
{
$reservations = [];
try {
$reservations = $reservationService->getByProject($project_id);
} catch (ServiceAction\Read $exception) {
return $this->withError($response, $exception);
}
return $this->withJson($response, compact('reservations'));
}
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
{ {
$output = [ $output = [
@ -60,8 +47,8 @@ class Reservations
'partial' => false, 'partial' => false,
'errors' => [], 'errors' => [],
]; ];
var_dump($input);
/*try { try {
$output['reservations'] []= [ $output['reservations'] []= [
'reservation' => $reservationService->add($input), 'reservation' => $reservationService->add($input),
'success' => true 'success' => true
@ -69,7 +56,7 @@ class Reservations
$output['partial'] = true; $output['partial'] = true;
} catch (ServiceAction\Create $exception) { } catch (ServiceAction\Create $exception) {
$output['errors'] []= $this->parseError($exception); $output['errors'] []= $this->parseError($exception);
}*/ }
if (count($input['reservations']) === count($output['reservations'])) { if (count($input['reservations']) === count($output['reservations'])) {
$output['success'] = true; $output['success'] = true;
@ -77,31 +64,6 @@ class Reservations
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function addOne(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService): ResponseInterface
{
$input = $request->getParsedBody();
$output = [
'input' => $input,
'reservation' => null,
'success' => false,
'errors' => [],
];
$data = [];
foreach ($input as $key => $value) {
if (!str_starts_with($key, 'add_')) {
continue;
}
$data[substr($key, 4)] = $value;
}
try {
$output['reservation'] = $reservationService->add($data);
$output['success'] = true;
} catch (ServiceAction\Create $exception) {
$output['errors'] []= $this->parseError($exception);
}
return $this->withJson($response, $output);
}
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
{ {
$input = $request->getParsedBody(); $input = $request->getParsedBody();
@ -138,76 +100,4 @@ class Reservations
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function active(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Reservation $reservationService, int $project_id): ResponseInterface
{
$output = [
'project_id' => $project_id,
'reservations' => [],
'success' => false,
];
try {
$output['reservations'] = $reservationService->getActive($project_id);
$output['success'] = true;
} catch (ServiceAction\Read) {}
return $this->withJson($response, $output);
}
public function pending(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Reservation $reservationService, int $project_id): ResponseInterface
{
$output = [
'project_id' => $project_id,
'reservations' => [],
'success' => false,
];
try {
$output['reservations'] = $reservationService->getPending($project_id);
$output['success'] = true;
} catch (ServiceAction\Read) {}
return $this->withJson($response, $output);
}
public function rejected(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Reservation $reservationService, int $project_id): ResponseInterface
{
$output = [
'project_id' => $project_id,
'reservations' => [],
'success' => false,
];
try {
$output['reservations'] = $reservationService->getRejected($project_id);
$output['success'] = true;
} catch (ServiceAction\Read) {}
return $this->withJson($response, $output);
}
public function approve(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
{
$output = [
'reservation_id' => $reservation_id,
'success' => false,
];
try {
$reservation = $reservationService->get($reservation_id);
$reservationService->approve($reservation);
$output['success'] = true;
} catch (ServiceAction\Read | ServiceAction\Update) {}
return $this->withJson($response, $output);
}
public function reject(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
{
$output = [
'reservation_id' => $reservation_id,
'success' => false,
];
try {
$reservation = $reservationService->get($reservation_id);
$reservationService->reject($reservation);
$output['success'] = true;
} catch (ServiceAction\Read | ServiceAction\Update) {}
return $this->withJson($response, $output);
}
} }

View File

@ -4,9 +4,6 @@ namespace Incoviba\Controller;
use Incoviba\Common\Alias\View; use Incoviba\Common\Alias\View;
use Incoviba\Common\Implement\Exception\EmptyRedis; use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Exception\ServiceAction\Update;
use Incoviba\Model; use Incoviba\Model;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Service; use Incoviba\Service;
@ -145,24 +142,9 @@ class Ventas
return $view->render($response, 'ventas.desistir', compact('venta')); return $view->render($response, 'ventas.desistir', compact('venta'));
} }
public function desistida(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, public function desistida(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
Service\Venta\Pago $pagoService,
View $view, int $venta_id): ResponseInterface View $view, int $venta_id): ResponseInterface
{ {
try { $venta = $ventaService->getById($venta_id);
$venta = $ventaService->getById($venta_id);
} catch (Read) {
return $view->render($response->withStatus(404), 'not_found');
}
if ($venta->resciliacion() === null) {
$pagoData = [
'fecha' => $venta->currentEstado()->fecha->format('Y-m-d'),
'valor' => 0
];
try {
$pago = $pagoService->add($pagoData);
$venta = $ventaService->edit($venta, ['resciliacion' => $pago->id]);
} catch (Create | Update) {}
}
return $view->render($response, 'ventas.desistida', compact('venta')); return $view->render($response, 'ventas.desistida', compact('venta'));
} }
} }

View File

@ -9,9 +9,9 @@ use Incoviba\Model;
class Precios class Precios
{ {
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService, ?int $project_id = null): ResponseInterface public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService): ResponseInterface
{ {
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles()); $proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
return $view->render($response, 'ventas.precios.list', compact('proyectos', 'project_id')); return $view->render($response, 'ventas.precios.list', compact('proyectos'));
} }
} }

View File

@ -1,28 +0,0 @@
<?php
namespace Incoviba\Controller\Ventas;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Alias\View;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Repository;
use Incoviba\Service;
class Reservations
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,
Service\Proyecto $proyectoService, Repository\Region $regionRepository,
View $view, ?int $project_id = null): ResponseInterface
{
$projects = [];
try {
$projects = $proyectoService->getVendibles('descripcion');
} catch (Read) {}
$regions = [];
try {
$regions = $regionRepository->fetchAll();
} catch (EmptyResult) {}
return $view->render($response, 'ventas.reservations', compact('projects', 'regions', 'project_id'));
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace Incoviba\Exception;
use Throwable;
use Exception;
abstract class MQTT extends Exception
{
public function __construct($message = "", $code = 0, ?Throwable $previous = null)
{
$baseCode = 700;
$code = $baseCode + $code;
if ($message == "") {
$message = "MQTT Exception";
}
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class MissingClient extends MQTT
{
public function __construct(string $host = '', ?Throwable $previous = null)
{
$message = 'Missing MQTT client';
if ($host !== '') {
$message = "{$message} for host {$host}";
}
$code = 1;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class MissingJob extends MQTT
{
public function __construct(?Throwable $previous = null)
{
$message = 'Missing MQTT job';
$code = 10;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class RemoveJob extends MQTT
{
public function __construct(int $jobId, ?Throwable $previous = null)
{
$message = "Could not remove job {$jobId}";
$code = 13;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class SetJob extends MQTT
{
public function __construct(string $payload, ?Throwable $previous = null)
{
$message = "Could not set job with {$payload}";
$code = 11;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace Incoviba\Exception\Model;
use Throwable;
use Exception;
class InvalidState extends Exception
{
public function __construct(string $message = "Invalid state", int $code = 505, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

View File

@ -7,14 +7,12 @@ class Job extends Ideal\Model
{ {
public array $configuration; public array $configuration;
public bool $executed = false; public bool $executed = false;
public int $retries = 0;
protected function jsonComplement(): array protected function jsonComplement(): array
{ {
return [ return [
'configuration' => $this->configuration, 'configuration' => $this->configuration,
'executed' => $this->executed, 'executed' => $this->executed
'retries' => $this->retries
]; ];
} }
} }

View File

@ -1,7 +1,6 @@
<?php <?php
namespace Incoviba\Model; namespace Incoviba\Model;
use Incoviba\Common\Implement\Exception\EmptyResult;
use InvalidArgumentException; use InvalidArgumentException;
use Incoviba\Common\Ideal; use Incoviba\Common\Ideal;
use Incoviba\Model\Persona\Datos; use Incoviba\Model\Persona\Datos;
@ -28,26 +27,22 @@ class Persona extends Ideal\Model
public function datos(): ?Datos public function datos(): ?Datos
{ {
if (!isset($this->datos)) { if (!isset($this->datos)) {
try { $this->datos = $this->runFactory('datos');
$this->datos = $this->runFactory('datos');
} catch (EmptyResult) {
$this->datos = null;
}
} }
return $this->datos; return $this->datos;
} }
public function __get(string $name): mixed public function __get(string $name): mixed
{ {
if (property_exists($this, $name)) {
return $this->{$name};
}
if ($name === 'datos') { if ($name === 'datos') {
return $this->datos(); return $this->datos();
} }
if ($name === 'dv') { if ($name === 'dv') {
return $this->digito; return $this->digito;
} }
if (property_exists($this, $name)) {
return $this->{$name};
}
throw new InvalidArgumentException("Property {$name} is not found in " . __CLASS__); throw new InvalidArgumentException("Property {$name} is not found in " . __CLASS__);
} }

View File

@ -21,11 +21,10 @@ class Datos extends Ideal\Model
public function jsonSerialize(): mixed public function jsonSerialize(): mixed
{ {
return [ return [
'persona_rut' => $this->persona->rut,
'direccion' => $this->direccion ?? null, 'direccion' => $this->direccion ?? null,
'telefono' => $this->telefono ?? null, 'telefono' => $this->telefono ?? null,
'email' => $this->email ?? null, 'email' => $this->email ?? null,
'fechaNacimiento' => $this->fechaNacimiento?->format('Y-m-d') ?? null, 'fechaNacimiento' => $this->fechaNacimiento ?? null,
'sexo' => $this->sexo ?? null, 'sexo' => $this->sexo ?? null,
'estadoCivil' => $this->estadoCivil ?? null, 'estadoCivil' => $this->estadoCivil ?? null,
'nacionalidad' => $this->nacionalidad ?? null, 'nacionalidad' => $this->nacionalidad ?? null,

View File

@ -1,10 +1,7 @@
<?php <?php
namespace Incoviba\Model\Proyecto; namespace Incoviba\Model\Proyecto;
use DateTimeImmutable;
use DateTimeInterface;
use Incoviba\Common; use Incoviba\Common;
use Incoviba\Model\Proyecto;
class Broker extends Common\Ideal\Model class Broker extends Common\Ideal\Model
{ {
@ -29,36 +26,6 @@ class Broker extends Common\Ideal\Model
} }
return $this->contracts; return $this->contracts;
} }
public function getContract(Proyecto $proyecto, ?DateTimeInterface $date = null): ?Proyecto\Broker\Contract
{
if ($date === null) {
$date = new DateTimeImmutable();
}
$contracts = $this->contracts();
$valid = array_filter($contracts, fn(Proyecto\Broker\Contract $contract) => $contract->project->id === $proyecto->id);
$valid = array_filter($valid, fn(Proyecto\Broker\Contract $contract) => $contract->wasActive($date));
if (count($valid) === 0) {
return null;
}
return last($valid);
}
public function applyCommission(Proyecto $proyecto, float $price, ?DateTimeInterface $date = null): float
{
$contract = $this->getContract($proyecto, $date);
if ($contract === null) {
return $price;
}
return $contract->activate()->apply($proyecto, $price);
}
public function reverseCommission(Proyecto $proyecto, float $price, ?DateTimeInterface $date = null): float
{
$contract = $this->getContract($proyecto, $date);
if ($contract === null) {
return $price;
}
return $contract->activate()->reverse($proyecto, $price);
}
public function rutFull(): string public function rutFull(): string
{ {

View File

@ -1,7 +1,6 @@
<?php <?php
namespace Incoviba\Model\Proyecto\Broker; namespace Incoviba\Model\Proyecto\Broker;
use DateTimeInterface;
use Incoviba\Common; use Incoviba\Common;
use Incoviba\Model; use Incoviba\Model;
@ -42,51 +41,6 @@ class Contract extends Common\Ideal\Model
return $this->promotions; return $this->promotions;
} }
public function isActive(): bool
{
$state = $this->current();
return $state !== null and $state->isActive();
}
public function activate(): self
{
$this->current()->activate();
return $this;
}
public function wasActive(DateTimeInterface $date): bool
{
$states = $this->states();
return array_any($states, fn($state) => $state->date <= $date);
}
public function value(float $price): float
{
if (!$this->isActive()) {
return $price;
}
return $price * (1 + $this->commission);
}
public function inverse(float $price): float
{
if (!$this->isActive()) {
return $price;
}
return $price / (1 + $this->commission);
}
public function apply(Model\Proyecto $project, float $price): float
{
if (!$this->isActive() or $this->project->id !== $project->id) {
return $price;
}
return $this->value($price);
}
public function reverse(Model\Proyecto $project, float $price): float
{
if (!$this->isActive() or $this->project->id !== $project->id) {
return $price;
}
return $this->inverse($price);
}
protected function jsonComplement(): array protected function jsonComplement(): array
{ {
return [ return [

View File

@ -11,16 +11,6 @@ class State extends Common\Ideal\Model
public DateTimeInterface $date; public DateTimeInterface $date;
public State\Type $type; public State\Type $type;
public function isActive(): bool
{
return $this->type === State\Type::ACTIVE;
}
public function activate(): self
{
$this->type = State\Type::ACTIVE;
return $this;
}
protected function jsonComplement(): array protected function jsonComplement(): array
{ {
return [ return [

View File

@ -1,7 +1,6 @@
<?php <?php
namespace Incoviba\Model\Venta; namespace Incoviba\Model\Venta;
use DateTimeInterface;
use JsonSerializable; use JsonSerializable;
use Incoviba\Model\Direccion; use Incoviba\Model\Direccion;
@ -13,7 +12,6 @@ class Datos
public ?Direccion $direccion = null; public ?Direccion $direccion = null;
public ?int $telefono = null; public ?int $telefono = null;
public ?string $email = null; public ?string $email = null;
public ?DateTimeInterface $fecha_nacimiento = null;
public function jsonSerialize(): mixed public function jsonSerialize(): mixed
{ {
@ -23,8 +21,7 @@ class Datos
'profesion' => $this->profesion ?? '', 'profesion' => $this->profesion ?? '',
'direccion' => $this->direccion ?? '', 'direccion' => $this->direccion ?? '',
'telefono' => $this->telefono ?? '', 'telefono' => $this->telefono ?? '',
'email' => $this->email ?? '', 'email' => $this->email ?? ''
'fecha_nacimiento' => $this->fecha_nacimiento?->format('Y-m-d') ?? '',
]; ];
} }
} }

View File

@ -3,7 +3,6 @@ namespace Incoviba\Model\Venta;
use DateTimeInterface; use DateTimeInterface;
use Incoviba\Common; use Incoviba\Common;
use Incoviba\Model\Proyecto;
use Incoviba\Model\Proyecto\Broker; use Incoviba\Model\Proyecto\Broker;
use Incoviba\Model\Venta\Promotion\State; use Incoviba\Model\Venta\Promotion\State;
use Incoviba\Model\Venta\Promotion\Type; use Incoviba\Model\Venta\Promotion\Type;
@ -62,95 +61,13 @@ class Promotion extends Common\Ideal\Model
return $this->units; return $this->units;
} }
public function isActive(): bool
{
return $this->state === State::ACTIVE;
}
public function activate(): self
{
$this->state = State::ACTIVE;
return $this;
}
public function value(float $price): float public function value(float $price): float
{ {
if (!$this->isActive()) {
return $price;
}
if ($this->type === Type::FIXED) { if ($this->type === Type::FIXED) {
return $price + $this->amount; return $price + $this->amount;
} }
return $price / (1 - $this->amount); return $price / (1 - $this->amount);
} }
public function inverse(float $price): float
{
if (!$this->isActive()) {
return $price;
}
if ($this->type === Type::FIXED) {
return $price - $this->amount;
}
return $price * (1 - $this->amount);
}
public function apply(Unidad $unit, float $price, ?Broker $broker = null): float
{
if (!$this->isActive()) {
return $price;
}
$projectIds = array_map(fn(Proyecto $proyecto) => $proyecto->id, $this->projects());
if (in_array($unit->proyectoTipoUnidad->proyecto->id, $projectIds)) {
return $this->value($price);
}
if ($broker !== null) {
$brokerIds = array_map(fn(Broker $broker) => $broker->id, $this->brokers());
if (in_array($broker->id, $brokerIds)) {
return $this->value($price);
}
}
$typeIds = array_map(fn(Proyecto\TipoUnidad $type) => $type->id, $this->unitTypes());
if (in_array($unit->proyectoTipoUnidad->tipoUnidad->id, $typeIds)) {
return $this->value($price);
}
$lineIds = array_map(fn(Proyecto\ProyectoTipoUnidad $line) => $line->id, $this->unitLines());
if (in_array($unit->proyectoTipoUnidad->id, $lineIds)) {
return $this->value($price);
}
$unitIds = array_map(fn(Unidad $unit) => $unit->id, $this->units());
if (in_array($unit->id, $unitIds)) {
return $this->value($price);
}
return $price;
}
public function reverse(Unidad $unit, float $price, ?Broker $broker = null): float
{
if (!$this->isActive()) {
return $price;
}
$projectIds = array_map(fn(Proyecto $proyecto) => $proyecto->id, $this->projects());
if (in_array($unit->proyectoTipoUnidad->proyecto->id, $projectIds)) {
return $this->inverse($price);
}
if ($broker !== null) {
$brokerIds = array_map(fn(Broker $broker) => $broker->id, $this->brokers());
if (in_array($broker->id, $brokerIds)) {
return $this->inverse($price);
}
}
$typeIds = array_map(fn(Proyecto\TipoUnidad $type) => $type->id, $this->unitTypes());
if (in_array($unit->proyectoTipoUnidad->tipoUnidad->id, $typeIds)) {
return $this->inverse($price);
}
$lineIds = array_map(fn(Proyecto\ProyectoTipoUnidad $line) => $line->id, $this->unitLines());
if (in_array($unit->proyectoTipoUnidad->id, $lineIds)) {
return $this->inverse($price);
}
$unitIds = array_map(fn(Unidad $unit) => $unit->id, $this->units());
if (in_array($unit->id, $unitIds)) {
return $this->inverse($price);
}
return $price;
}
protected function jsonComplement(): array protected function jsonComplement(): array
{ {

View File

@ -4,53 +4,19 @@ namespace Incoviba\Model\Venta;
use DateTimeInterface; use DateTimeInterface;
use Incoviba\Common; use Incoviba\Common;
use Incoviba\Model; use Incoviba\Model;
use InvalidArgumentException;
class Reservation extends Common\Ideal\Model class Reservation extends Common\Ideal\Model
{ {
public Model\Proyecto $project;
public Model\Persona $buyer; public Model\Persona $buyer;
public DateTimeInterface $date; public DateTimeInterface $date;
public array $units = []; public array $units = [];
public array $promotions = []; public array $promotions = [];
public ?Model\Proyecto\Broker $broker = null; public ?Model\Proyecto\Broker $broker = null;
public function offer(): float
{
return array_sum(array_column($this->units, 'value'));
}
public function withCommission(): float
{
$base = 0;
foreach ($this->units as $unit) {
foreach ($this->promotions as $promotion) {
$base += $promotion->activate()->reverse($unit['unit'], $unit['value'], $this->broker);
}
}
return $base;
}
public function base(): float
{
$base = $this->withCommission();
if ($this->broker !== null) {
$base = $this->broker->reverseCommission($this->project, $base, $this->date);
}
return $base;
}
public function price(): float
{
$price = 0;
foreach ($this->units as $unit) {
$price += $unit->unit->precio($this->date)?->valor ?? 0;
}
return $price;
}
protected array $states = []; protected array $states = [];
public function states(): array public function states(): array
{ {
if (count($this->states) === 0) { if (!isset($this->states)) {
$this->states = $this->runFactory('states'); $this->states = $this->runFactory('states');
} }
return $this->states; return $this->states;
@ -61,11 +27,7 @@ class Reservation extends Common\Ideal\Model
public function currentState(): Model\Venta\Reservation\State public function currentState(): Model\Venta\Reservation\State
{ {
if (!isset($this->currentState)) { if (!isset($this->currentState)) {
$states = $this->states(); $this->currentState = last($this->states());
if (count($states) === 0) {
throw new InvalidArgumentException('States must not be empty');
}
$this->currentState = last($states);
} }
return $this->currentState; return $this->currentState;
} }
@ -73,15 +35,16 @@ class Reservation extends Common\Ideal\Model
public function addUnit(Model\Venta\Unidad $unit, float $value): self public function addUnit(Model\Venta\Unidad $unit, float $value): self
{ {
if (($i = $this->findUnit($unit->id)) !== null) { if (($i = $this->findUnit($unit->id)) !== null) {
$this->units[$i]->value = $value; $this->units[$i]['value'] = $value;
return $this; return $this;
} }
$this->units[] = (object) [ $this->units[] = [
'unit' => $unit, 'unit' => $unit,
'value' => $value, 'value' => $value,
]; ];
return $this; return $this;
} }
public function removeUnit(int $unit_id): self public function removeUnit(int $unit_id): self
{ {
if (($i = $this->findUnit($unit_id)) === null) { if (($i = $this->findUnit($unit_id)) === null) {
@ -91,47 +54,30 @@ class Reservation extends Common\Ideal\Model
$this->units = array_values($this->units); $this->units = array_values($this->units);
return $this; return $this;
} }
public function findUnit(int $unit_id): ?int public function findUnit(int $unit_id): ?int
{ {
return array_find_key($this->units, fn($unit) => $unit->unit->id == $unit_id); foreach ($this->units as $idx => $unit) {
if ($unit['unit']->id == $unit_id) {
return $idx;
}
}
return null;
} }
public function hasUnit(int $unit_id): bool public function hasUnit(int $unit_id): bool
{ {
return $this->findUnit($unit_id) !== null; return $this->findUnit($unit_id) !== null;
} }
public function summary(): string
{
$unitSummary = array_map(function($unit) {
$type = $unit->unit->proyectoTipoUnidad->tipoUnidad->descripcion;
$cap = strtoupper(strstr($type, 0, 1));
return "{$cap}{$unit->unit->descripcion}";
}, $this->units);
return implode('', $unitSummary);
}
public function valid(): bool
{
$base = $this->base();
$price = $this->price();
return $base >= $price;
}
protected function jsonComplement(): array protected function jsonComplement(): array
{ {
return [ return [
'project_id' => $this->project->id, 'buyer_rut' => $this->buyer->rut,
'buyer' => $this->buyer,
'date' => $this->date->format('Y-m-d'), 'date' => $this->date->format('Y-m-d'),
'units' => $this->units, 'units' => $this->units,
'promotions' => $this->promotions, 'promotions' => $this->promotions,
'broker' => $this->broker, 'broker_rut' => $this->broker?->rut,
'offer' => $this->offer(),
'with_commission' => $this->withCommission(),
'base' => $this->base(),
'price' => $this->price(),
'valid' => $this->valid(),
'summary' => $this->summary()
]; ];
} }
} }

View File

@ -1,17 +0,0 @@
<?php
namespace Incoviba\Model\Venta\Reservation\Detail;
enum Type: int
{
case Unit = 1;
case Promotion = 2;
case Broker = 3;
public function jsonSerialize(): array
{
return [
'id' => $this->value,
'description' => $this->name
];
}
}

View File

@ -9,14 +9,17 @@ class State extends Common\Ideal\Model
{ {
public Model\Venta\Reservation $reservation; public Model\Venta\Reservation $reservation;
public DateTimeInterface $date; public DateTimeInterface $date;
public Model\Venta\Reservation\State\Type $type; public int $type;
protected function jsonComplement(): array protected function jsonComplement(): array
{ {
return [ return [
'reservation_id' => $this->reservation->id, 'reservation_id' => $this->reservation->id,
'date' => $this->date->format('Y-m-d'), 'date' => $this->date->format('Y-m-d'),
'type' => $this->type 'type' => [
'id' => $this->type,
'description' => State\Type::name($this->type)
]
]; ];
} }
} }

View File

@ -3,21 +3,17 @@ namespace Incoviba\Model\Venta\Reservation\State;
enum Type: int enum Type: int
{ {
case INACTIVE = 0;
case ACTIVE = 1; case ACTIVE = 1;
case PROMISED = 2; case INACTIVE = 0;
case REJECTED = -1; case REJECTED = -1;
case CANCELLED = -2;
public function jsonSerialize(): array public static function name(int $type): string
{ {
return [ return match ($type) {
'id' => $this->value, self::ACTIVE => 'active',
'description' => $this->name self::INACTIVE => 'inactive',
]; self::REJECTED => 'rejected',
} default => throw new \InvalidArgumentException('Unexpected match value')
public static function getTypes(): array };
{
return [self::ACTIVE->value, self::INACTIVE->value, self::REJECTED->value];
} }
} }

View File

@ -43,11 +43,6 @@ class Inmobiliaria extends Ideal\Repository
return $this->update($model, ['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'], $new_data); return $this->update($model, ['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'], $new_data);
} }
/**
* @param string|array|null $sorting
* @return array
* @throws Implement\Exception\EmptyResult
*/
public function fetchAllActive(null|string|array $sorting = null): array public function fetchAllActive(null|string|array $sorting = null): array
{ {
$query = $this->connection->getQueryBuilder() $query = $this->connection->getQueryBuilder()
@ -63,18 +58,4 @@ class Inmobiliaria extends Ideal\Repository
} }
return $this->fetchMany($query, [1, 8]); return $this->fetchMany($query, [1, 8]);
} }
/**
* @param string $name
* @return Model\Inmobiliaria
* @throws Implement\Exception\EmptyResult
*/
public function fetchByName(string $name): Model\Inmobiliaria
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('razon LIKE :name OR abreviacion LIKE :name');
return $this->fetchOne($query, ['name' => "%{$name}%"]);
}
} }

View File

@ -29,9 +29,6 @@ class Datos extends Ideal\Repository
->register('direccion_id', (new Implement\Repository\Mapper()) ->register('direccion_id', (new Implement\Repository\Mapper())
->setProperty('direccion') ->setProperty('direccion')
->setFunction(function($data) { ->setFunction(function($data) {
if ($data['direccion_id'] === null) {
return null;
}
return $this->direccionRepository->fetchById($data['direccion_id']); return $this->direccionRepository->fetchById($data['direccion_id']);
})->setDefault(null)) })->setDefault(null))
->register('telefono', (new Implement\Repository\Mapper())->setFunction(function($data) { ->register('telefono', (new Implement\Repository\Mapper())->setFunction(function($data) {
@ -59,7 +56,7 @@ class Datos extends Ideal\Repository
} }
public function save(Define\Model $model): Model\Persona\Datos public function save(Define\Model $model): Model\Persona\Datos
{ {
$model->id = $this->saveNew([ $this->saveNew([
'persona_rut', 'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil', 'persona_rut', 'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
'nacionalidad', 'ocupacion' 'nacionalidad', 'ocupacion'
], [ ], [
@ -116,11 +113,4 @@ class Datos extends Ideal\Repository
} }
$this->connection->execute($query, $flattened); $this->connection->execute($query, $flattened);
} }
public function filterData(array $data): array
{
$fields = ['persona_rut', 'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
'nacionalidad', 'ocupacion'];
return array_intersect_key($data, array_flip($fields));
}
} }

View File

@ -85,11 +85,6 @@ class Proyecto extends Ideal\Repository
return $this->fetchOne($query, [$id]); return $this->fetchOne($query, [$id]);
} }
/**
* @param string $name
* @return Model\Proyecto
* @throws Implement\Exception\EmptyResult
*/
public function fetchByName(string $name): Model\Proyecto public function fetchByName(string $name): Model\Proyecto
{ {
$query = $this->connection->getQueryBuilder() $query = $this->connection->getQueryBuilder()

View File

@ -93,7 +93,7 @@ class Contract extends Common\Ideal\Repository
->select('a.*') ->select('a.*')
->from("{$this->getTable()} a") ->from("{$this->getTable()} a")
->joined($this->statusJoin()) ->joined($this->statusJoin())
->where('a.broker_rut = :broker_rut AND bcs.type = :state'); ->where('a.broker_rut = :broker_rut AND bcs.state = :state');
return $this->fetchMany($query, ['broker_rut' => $brokerRut, 'state' => Model\Proyecto\Broker\Contract\Type::ACTIVE]); return $this->fetchMany($query, ['broker_rut' => $brokerRut, 'state' => Model\Proyecto\Broker\Contract\Type::ACTIVE]);
} }
@ -108,8 +108,8 @@ class Contract extends Common\Ideal\Repository
->select('a.*') ->select('a.*')
->from("{$this->getTable()} a") ->from("{$this->getTable()} a")
->joined($this->statusJoin()) ->joined($this->statusJoin())
->where('a.project_id = :project_id AND bcs.type = :state'); ->where('a.proyecto_id = :proyecto_id AND bcs.state = :state');
return $this->fetchMany($query, ['project_id' => $projectId, 'state' => Model\Proyecto\Broker\Contract\State\Type::ACTIVE->value]); return $this->fetchMany($query, ['proyecto_id' => $projectId, 'state' => Model\Proyecto\Broker\Contract\State\Type::ACTIVE->value]);
} }
/** /**

View File

@ -7,8 +7,6 @@ use Incoviba\Common\Define;
use Incoviba\Common\Implement; use Incoviba\Common\Implement;
use Incoviba\Model; use Incoviba\Model;
use Incoviba\Repository; use Incoviba\Repository;
use PDO;
use PDOException;
class EstadoPrecio extends Ideal\Repository class EstadoPrecio extends Ideal\Repository
{ {
@ -46,22 +44,11 @@ class EstadoPrecio extends Ideal\Repository
return $this->update($model, ['precio', 'estado', 'fecha'], $new_data); return $this->update($model, ['precio', 'estado', 'fecha'], $new_data);
} }
/**
* @param int $precio_id
* @return array
* @throws Implement\Exception\EmptyResult
*/
public function fetchByPrecio(int $precio_id): array public function fetchByPrecio(int $precio_id): array
{ {
$query = "SELECT * FROM `{$this->getTable()}` WHERE `precio` = ?"; $query = "SELECT * FROM `{$this->getTable()}` WHERE `precio` = ?";
return $this->fetchMany($query, [$precio_id]); return $this->fetchMany($query, [$precio_id]);
} }
/**
* @param int $precio_id
* @return Define\Model
* @throws Implement\Exception\EmptyResult
*/
public function fetchCurrentByPrecio(int $precio_id): Define\Model public function fetchCurrentByPrecio(int $precio_id): Define\Model
{ {
$query = "SELECT e1.* $query = "SELECT e1.*

View File

@ -1,7 +1,6 @@
<?php <?php
namespace Incoviba\Repository\Venta; namespace Incoviba\Repository\Venta;
use Incoviba\Common\Implement\Exception\EmptyResult;
use PDO; use PDO;
use PDOException; use PDOException;
use Incoviba\Common\Ideal; use Incoviba\Common\Ideal;

View File

@ -212,7 +212,7 @@ class Promotion extends Common\Ideal\Repository
->joined('LEFT OUTER JOIN proyecto_tipo_unidad ptu1 ON ptu.id = unidad.pt') ->joined('LEFT OUTER JOIN proyecto_tipo_unidad ptu1 ON ptu.id = unidad.pt')
->where('(pp.project_id = :project_id OR put.project_id = :project_id OR ptu.proyecto = :project_id OR ptu1.proyecto = :project_id) AND a.state = :state') ->where('(pp.project_id = :project_id OR put.project_id = :project_id OR ptu.proyecto = :project_id OR ptu1.proyecto = :project_id) AND a.state = :state')
->group('a.id'); ->group('a.id');
return $this->fetchMany($query, ['project_id' => $project_id, 'state' => Model\Venta\Promotion\State::ACTIVE->value]); return $this->fetchMany($query, ['project_id' => $project_id, 'state' => Model\Venta\Promotion\State::ACTIVE]);
} }
/** /**

View File

@ -3,19 +3,14 @@ namespace Incoviba\Repository\Venta;
use DateTimeInterface; use DateTimeInterface;
use DateInterval; use DateInterval;
use Incoviba\Common\Define;
use Incoviba\Exception\Model\InvalidState;
use PDO; use PDO;
use Incoviba\Common; use Incoviba\Common;
use Incoviba\Model; use Incoviba\Model;
use Incoviba\Repository; use Incoviba\Repository;
use PDOException;
class Reservation extends Common\Ideal\Repository class Reservation extends Common\Ideal\Repository
{ {
public function __construct(Common\Define\Connection $connection, public function __construct(Common\Define\Connection $connection, protected Repository\Persona $personaRepository,
protected Repository\Proyecto $proyectoRepository,
protected Repository\Persona $personaRepository,
protected Repository\Proyecto\Broker $brokerRepository, protected Repository\Proyecto\Broker $brokerRepository,
protected Unidad $unitRepository, protected Promotion $promotionRepository) protected Unidad $unitRepository, protected Promotion $promotionRepository)
{ {
@ -30,35 +25,37 @@ class Reservation extends Common\Ideal\Repository
public function create(?array $data = null): Model\Venta\Reservation public function create(?array $data = null): Model\Venta\Reservation
{ {
$map = (new Common\Implement\Repository\MapperParser()) $map = (new Common\Implement\Repository\MapperParser())
->register('project_id', (new Common\Implement\Repository\Mapper())
->setProperty('project')
->setFunction(function($data) {
return $this->proyectoRepository->fetchById($data['project_id']);
}))
->register('buyer_rut', (new Common\Implement\Repository\Mapper()) ->register('buyer_rut', (new Common\Implement\Repository\Mapper())
->setProperty('buyer') ->setProperty('buyer')
->setFunction(function($data) { ->setFunction(function($data) use ($data) {
return $this->personaRepository->fetchById($data['buyer_rut']); return $this->personaRepository->fetchById($data['buyer_rut']);
})) }))
->register('date', new Common\Implement\Repository\Mapper\DateTime('date')); ->register('date', new Common\Implement\Repository\Mapper\DateTime('date'))
->register('broker_rut', (new Common\Implement\Repository\Mapper())
->setProperty('broker')
->setDefault(null)
->setFunction(function($data) use ($data) {
try {
return $this->brokerRepository->fetchById($data['broker_rut']);
} catch (Common\Implement\Exception\EmptyResult) {
return null;
}
}));
return $this->parseData(new Model\Venta\Reservation(), $data, $map); return $this->parseData(new Model\Venta\Reservation(), $data, $map);
} }
public function save(Common\Define\Model $model): Model\Venta\Reservation public function save(Common\Define\Model $model): Model\Venta\Reservation
{ {
if (!isset($model->id)) { $model->id = $this->saveNew([
$model->id = $this->saveNew([ 'buyer_rut',
'project_id', 'date',
'buyer_rut', 'broker_rut'
'date' ], [
], [ $model->buyer->rut,
$model->project->id, $model->date->format('Y-m-d'),
$model->buyer->rut, $model->broker?->rut
$model->date->format('Y-m-d') ]);
]);
}
$this->saveUnits($model); $this->saveUnits($model);
$this->savePromotions($model); $this->savePromotions($model);
$this->saveBroker($model);
return $model; return $model;
} }
@ -70,22 +67,15 @@ class Reservation extends Common\Ideal\Repository
*/ */
public function edit(Common\Define\Model $model, array $new_data): Model\Venta\Reservation public function edit(Common\Define\Model $model, array $new_data): Model\Venta\Reservation
{ {
$model = $this->update($model, ['project_id', 'buyer_rut', 'date'], $new_data); return $this->update($model, ['buyer_rut', 'date', 'broker_rut'], $new_data);
$this->editUnits($model, $new_data);
$this->editPromotions($model, $new_data);
$this->editBroker($model, $new_data);
return $model;
} }
public function load(array $data_row): Model\Venta\Reservation public function load(array $data_row): Model\Venta\Reservation
{ {
$model = parent::load($data_row); $model = parent::load($data_row);
$this->fetchUnits($model, $data_row); $this->fetchUnits($model);
try { $this->fetchPromotions($model);
$this->fetchBroker($model, $data_row);
} catch (Common\Implement\Exception\EmptyResult) {}
$this->fetchPromotions($model, $data_row);
return $model; return $model;
} }
@ -103,88 +93,6 @@ class Reservation extends Common\Ideal\Repository
->where('buyer_rut = :buyer_rut AND date >= :date'); ->where('buyer_rut = :buyer_rut AND date >= :date');
return $this->fetchOne($query, ['buyer_rut' => $buyer_rut, 'date' => $date->sub(new DateInterval('P10D'))->format('Y-m-d')]); return $this->fetchOne($query, ['buyer_rut' => $buyer_rut, 'date' => $date->sub(new DateInterval('P10D'))->format('Y-m-d')]);
} }
public function fetchByProject(int $project_id): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from('reservations')
->where('project_id = :project_id');
return $this->fetchMany($query, ['project_id' => $project_id]);
}
/**
* @param int $project_id
* @param int $state
* @return array
* @throws Common\Implement\Exception\EmptyResult
* @throws InvalidState
*/
public function fetchState(int $project_id, int $state): array
{
if (!in_array($state, Model\Venta\Reservation\State\Type::getTypes())) {
throw new InvalidState();
}
$sub1 = $this->connection->getQueryBuilder()
->select('MAX(id) AS id, reservation_id')
->from('reservation_states')
->group('reservation_id');
$sub2 = $this->connection->getQueryBuilder()
->select('er1.*')
->from('reservation_states er1')
->joined("INNER JOIN ({$sub1}) er0 ON er0.id = er1.id");
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined("INNER JOIN ({$sub2}) er ON er.reservation_id = a.id")
->where('a.project_id = :project_id AND er.type = :state');
return $this->fetchMany($query, ['project_id' => $project_id,
'state' => $state]);
}
/**
* @param int $project_id
* @return array
* @throws Common\Implement\Exception\EmptyResult
*/
public function fetchActive(int $project_id): array
{
try {
return $this->fetchState($project_id, Model\Venta\Reservation\State\Type::ACTIVE->value);
} catch (InvalidState $exception) {
throw new Common\Implement\Exception\EmptyResult('Select active reservations', $exception);
}
}
/**
* @param int $project_id
* @return array
* @throws Common\Implement\Exception\EmptyResult
*/
public function fetchPending(int $project_id): array
{
try {
return $this->fetchState($project_id, Model\Venta\Reservation\State\Type::INACTIVE->value);
} catch (InvalidState $exception) {
throw new Common\Implement\Exception\EmptyResult('Select pending reservations', $exception);
}
}
/**
* @param int $project_id
* @return array
* @throws Common\Implement\Exception\EmptyResult
*/
public function fetchRejected(int $project_id): array
{
try {
return [
...$this->fetchState($project_id, Model\Venta\Reservation\State\Type::REJECTED->value),
...$this->fetchState($project_id, Model\Venta\Reservation\State\Type::CANCELLED->value)
];
} catch (InvalidState $exception) {
throw new Common\Implement\Exception\EmptyResult('Select rejected reservations', $exception);
}
}
protected function saveUnits(Model\Venta\Reservation $reservation): void protected function saveUnits(Model\Venta\Reservation $reservation): void
{ {
@ -193,74 +101,22 @@ class Reservation extends Common\Ideal\Repository
} }
$queryCheck = $this->connection->getQueryBuilder() $queryCheck = $this->connection->getQueryBuilder()
->select('COUNT(id) AS cnt') ->select('COUNT(id) AS cnt')
->from('reservation_details') ->from('reservation_data')
->where('reservation_id = :id AND type = :type AND reference_id = :unit_id'); ->where('reservation_id = :id AND type = "Unit" AND reference_id = :unit_id');
$statementCheck = $this->connection->prepare($queryCheck); $statementCheck = $this->connection->prepare($queryCheck);
$queryInsert = $this->connection->getQueryBuilder() $queryInsert = $this->connection->getQueryBuilder()
->insert() ->insert()
->into('reservation_details') ->into('reservation_data')
->columns(['reservation_id', 'type', 'reference_id', 'value']) ->columns(['reservation_id', 'type', 'reference_id', 'value'])
->values([':reservation_id', ':type', ':reference_id', ':value']); ->values([':reservation_id', ':type', ':reference_id', ':value']);
$statementInsert = $this->connection->prepare($queryInsert); $statementInsert = $this->connection->prepare($queryInsert);
foreach ($reservation->units as $unit) { foreach ($reservation->units as $unit) {
$statementCheck->execute([ $statementCheck->execute(['id' => $reservation->id, 'unit_id' => $unit['unit']->id]);
'id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Unit->value,
'unit_id' => $unit->unit->id
]);
$result = $statementCheck->fetch(PDO::FETCH_ASSOC); $result = $statementCheck->fetch(PDO::FETCH_ASSOC);
if ($result['cnt'] > 0) { if ($result['cnt'] > 0) {
continue; continue;
} }
$statementInsert->execute([ $statementInsert->execute(['reservation_id' => $reservation->id, 'type' => 'Unit', 'reference_id' => $unit['unit']->id, 'value' => $unit['value']]);
'reservation_id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Unit->value,
'reference_id' => $unit->unit->id,
'value' => $unit->value
]);
}
$this->cleanUpUnits($reservation);
}
protected function cleanUpUnits(Model\Venta\Reservation $reservation): void
{
$this->cleanUpDetails($reservation,
Model\Venta\Reservation\Detail\Type::Unit->value,
array_map(fn($unit) => $unit->unit->id, $reservation->units));
}
protected function saveBroker(Model\Venta\Reservation &$reservation): void
{
if ($reservation->broker === null) {
$this->removeBroker($reservation);
return;
}
try {
$queryCheck = $this->connection->getQueryBuilder()
->select('reference_id')
->from('reservation_details')
->where('reservation_id = :id AND type = :type');
$statementCheck = $this->connection->execute($queryCheck, [
'id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Broker->value
]);
$result = $statementCheck->fetch(PDO::FETCH_ASSOC);
if ($result === false) {
throw new PDOException();
}
$new_id = $reservation->broker->rut;
$reservation->broker = $this->brokerRepository->fetchById($result['reference_id']);
$this->editBroker($reservation, ['broker_rut' => $new_id]);
} catch (PDOException) {
$queryInsert = $this->connection->getQueryBuilder()
->insert()
->into('reservation_details')
->columns(['reservation_id', 'type', 'reference_id'])
->values([':reservation_id', ':type', ':reference_id']);
$this->connection->execute($queryInsert, [
'reservation_id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Broker->value,
'reference_id' => $reservation->broker->rut
]);
} }
} }
protected function savePromotions(Model\Venta\Reservation $reservation): void protected function savePromotions(Model\Venta\Reservation $reservation): void
@ -270,152 +126,60 @@ class Reservation extends Common\Ideal\Repository
} }
$queryCheck = $this->connection->getQueryBuilder() $queryCheck = $this->connection->getQueryBuilder()
->select('COUNT(id) AS cnt') ->select('COUNT(id) AS cnt')
->from('reservation_details') ->from('reservation_data')
->where('reservation_id = :id AND type = :type AND reference_id = :promotion_id'); ->where('reservation_id = :id AND type = "Promotion" AND reference_id = :promotion_id');
$statementCheck = $this->connection->prepare($queryCheck); $statementCheck = $this->connection->prepare($queryCheck);
$queryInsert = $this->connection->getQueryBuilder() $queryInsert = $this->connection->getQueryBuilder()
->insert() ->insert()
->into('reservation_details') ->into('reservation_data')
->columns(['reservation_id', 'type', 'reference_id']) ->columns(['reservation_id', 'type', 'reference_id'])
->values([':reservation_id', ':type', ':reference_id']); ->values([':reservation_id', ':type', ':reference_id']);
$statementInsert = $this->connection->prepare($queryInsert); $statementInsert = $this->connection->prepare($queryInsert);
foreach ($reservation->promotions as $promotion) { foreach ($reservation->promotions as $promotion) {
$statementCheck->execute([ $statementCheck->execute(['id' => $reservation->id, 'promotion_id' => $promotion->id]);
'id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Promotion->value,
'promotion_id' => $promotion->id
]);
$result = $statementCheck->fetch(PDO::FETCH_ASSOC); $result = $statementCheck->fetch(PDO::FETCH_ASSOC);
if ($result['cnt'] > 0) { if ($result['cnt'] > 0) {
continue; continue;
} }
$statementInsert->execute([ $statementInsert->execute(['reservation_id' => $reservation->id, 'type' => 'Promotion', 'reference_id' => $promotion->id]);
'reservation_id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Promotion->value,
'reference_id' => $promotion->id
]);
} }
$this->cleanUpPromotions($reservation);
} }
protected function cleanUpPromotions(Model\Venta\Reservation $reservation): void protected function editUnits(Model\Venta\Reservation $reservation, array $new_data): void
{
$this->cleanUpDetails($reservation,
Model\Venta\Reservation\Detail\Type::Promotion->value,
array_map(fn($promotion) => $promotion->id, $reservation->promotions));
}
protected function cleanUpDetails(Model\Venta\Reservation $reservation, int $type_id, array $currentIds): void
{
$queryCheck = $this->connection->getQueryBuilder()
->select('COUNT(id) AS cnt')
->from('reservation_details')
->where('reservation_id = :id AND type = :type');
$statementCheck = $this->connection->prepare($queryCheck);
$deleteParam = implode(', ', array_map(fn($id) => ":id$id", $currentIds));
$queryDelete = $this->connection->getQueryBuilder()
->delete()
->from('reservation_details')
->where("reservation_id = :id AND type = :type AND reference_id NOT IN ({$deleteParam})");
$statementDelete = $this->connection->prepare($queryDelete);
try {
$statementCheck->execute([
'id' => $reservation->id,
'type' => $type_id
]);
$result = $statementCheck->fetch(PDO::FETCH_ASSOC);
if ($result['cnt'] <= count($currentIds)) {
return;
}
$deleteIdValues = array_combine(array_map(fn($id) => "id$id", $currentIds), $currentIds);
$statementDelete->execute(array_merge(
['id' => $reservation->id, 'type' => $type_id],
$deleteIdValues));
} catch (PDOException) {}
}
protected function editUnits(Model\Venta\Reservation &$reservation, array $new_data): void
{ {
$querySelect = $this->connection->getQueryBuilder() $querySelect = $this->connection->getQueryBuilder()
->select() ->select()
->from('reservation_details') ->from('reservation_data')
->where('reservation_id = :id AND type = :type AND reference_id = :unit_id'); ->where('reservation_id = :id AND type = "Unit" AND reference_id = :unit_id');
$statementSelect = $this->connection->prepare($querySelect); $statementSelect = $this->connection->prepare($querySelect);
$queryUpdate = $this->connection->getQueryBuilder() $queryUpdate = $this->connection->getQueryBuilder()
->update('reservation_details') ->update('reservation_data')
->set('value = :value') ->set('value = :value')
->where('reservation_id = :id AND type = :type AND reference_id = :unit_id'); ->where('reservation_id = :id AND type = "Unit" AND reference_id = :unit_id');
$statementUpdate = $this->connection->prepare($queryUpdate); $statementUpdate = $this->connection->prepare($queryUpdate);
$queryInsert = $this->connection->getQueryBuilder() foreach ($new_data as $unit_id => $value) {
->insert() $idx = $reservation->findUnit($unit_id);
->into('reservation_details')
->columns(['reservation_id', 'type', 'reference_id', 'value'])
->values([':reservation_id', ':type', ':reference_id', ':value']);
$statementInsert = $this->connection->prepare($queryInsert);
foreach ($new_data['units'] as $unit) {
$idx = $reservation->findUnit($unit['unit_id']);
if ($idx === null) { if ($idx === null) {
$reservation->addUnit($this->unitRepository->fetchById($unit['unit_id']), $unit['value']); $reservation->addUnit($this->unitRepository->fetchById($unit_id), $value);
$statementInsert->execute([
'reservation_id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Unit->value,
'reference_id' => $unit['unit_id'],
'value' => $unit['value']
]);
continue; continue;
} }
$statementSelect->execute([ $statementSelect->execute(['id' => $reservation->id, 'unit_id' => $unit_id]);
'id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Unit->value,
'unit_id' => $unit['unit_id']
]);
$result = $statementSelect->fetch(PDO::FETCH_ASSOC); $result = $statementSelect->fetch(PDO::FETCH_ASSOC);
if (!$result) { if (!$result) {
$reservation->addUnit($this->unitRepository->fetchById($unit['unit_id']), $unit['value']);
$statementInsert->execute([
'reservation_id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Unit->value,
'reference_id' => $unit['unit_id'],
'value' => $unit['value']
]);
continue; continue;
} }
$statementUpdate->execute([ $statementUpdate->execute(['id' => $reservation->id, 'unit_id' => $unit_id, 'value' => $value]);
'id' => $reservation->id, $reservation->units[$idx]['value'] = $value;
'type' => Model\Venta\Reservation\Detail\Type::Unit->value,
'unit_id' => $unit['unit_id'],
'value' => $unit['value']
]);
$reservation->units[$idx]['value'] = $unit['value'];
} }
} }
protected function editBroker(Model\Venta\Reservation &$reservation, array $new_data): void protected function editPromotions(Model\Venta\Reservation $reservation, array $new_data): void
{
if (!array_key_exists('broker_rut', $new_data) or $new_data['broker_rut'] === $reservation->broker->rut) {
return;
}
try {
$query = $this->connection->getQueryBuilder()
->update('reservation_details')
->set('reference_id = :broker_rut')
->where('reservation_id = :id AND type = :type');
$this->connection->execute($query, [
'id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Broker->value,
'broker_rut' => $new_data['broker_rut']
]);
$reservation->broker = $this->brokerRepository->fetchById($new_data['broker_rut']);
} catch (PDOException) {}
}
protected function editPromotions(Model\Venta\Reservation &$reservation, array $new_data): void
{ {
$querySelect = $this->connection->getQueryBuilder() $querySelect = $this->connection->getQueryBuilder()
->select() ->select()
->from('reservation_details') ->from('reservation_data')
->where('reservation_id = :id AND type = "Promotion" AND reference_id = :promotion_id'); ->where('reservation_id = :id AND type = "Promotion" AND reference_id = :promotion_id');
$statementSelect = $this->connection->prepare($querySelect); $statementSelect = $this->connection->prepare($querySelect);
$queryUpdate = $this->connection->getQueryBuilder() $queryUpdate = $this->connection->getQueryBuilder()
->update('reservation_details') ->update('reservation_data')
->set('value = :value') ->set('value = :value')
->where('reservation_id = :id AND type = "Promotion" AND reference_id = :promotion_id'); ->where('reservation_id = :id AND type = "Promotion" AND reference_id = :promotion_id');
$statementUpdate = $this->connection->prepare($queryUpdate); $statementUpdate = $this->connection->prepare($queryUpdate);
@ -434,26 +198,13 @@ class Reservation extends Common\Ideal\Repository
$reservation->promotions[$idx] = $this->promotionRepository->fetchById($promotion_id); $reservation->promotions[$idx] = $this->promotionRepository->fetchById($promotion_id);
} }
} }
protected function fetchUnits(Model\Venta\Reservation &$reservation): Model\Venta\Reservation
protected function fetchUnits(Model\Venta\Reservation &$reservation, array $new_data): Model\Venta\Reservation
{
$this->fetchSavedUnits($reservation);
if (array_key_exists('units', $new_data) and count($new_data['units']) > 0) {
$this->fetchUnsavedUnits($reservation, $new_data);
}
return $reservation;
}
protected function fetchSavedUnits(Model\Venta\Reservation &$reservation): Model\Venta\Reservation
{ {
$query = $this->connection->getQueryBuilder() $query = $this->connection->getQueryBuilder()
->select() ->select()
->from('reservation_details') ->from('reservation_data')
->where('reservation_id = :id AND type = :type'); ->where('reservation_id = :id AND type = "Unit"');
$statement = $this->connection->execute($query, [ $statement = $this->connection->execute($query, ['id' => $reservation->id]);
'id' => $reservation->id,
'type' =>Model\Venta\Reservation\Detail\Type::Unit->value
]);
while ($result = $statement->fetch(PDO::FETCH_ASSOC)) { while ($result = $statement->fetch(PDO::FETCH_ASSOC)) {
try { try {
@ -462,79 +213,13 @@ class Reservation extends Common\Ideal\Repository
} }
return $reservation; return $reservation;
} }
protected function fetchUnsavedUnits(Model\Venta\Reservation &$reservation, array $new_data): Model\Venta\Reservation protected function fetchPromotions(Model\Venta\Reservation $reservation): Model\Venta\Reservation
{
if (!array_key_exists('units', $new_data) or count($new_data['units']) > 0) {
return $reservation;
}
$queryCheck = $this->connection->getQueryBuilder()
->select('COUNT(id) AS cnt')
->from('reservation_details')
->where('reservation_id = :id AND type = :type AND reference_id = :unit_id');
$statementCheck = $this->connection->prepare($queryCheck);
foreach ($new_data['units'] as $unit) {
$statementCheck->execute([
'id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Unit->value,
'unit_id' => $unit['unit_id']
]);
$result = $statementCheck->fetch(PDO::FETCH_ASSOC);
if ($result['cnt'] > 0) {
continue;
}
try {
$reservation->addUnit($this->unitRepository->fetchById($unit['unit_id']), $unit['value']);
} catch (Common\Implement\Exception\EmptyResult) {}
}
return $reservation;
}
/**
* @param Model\Venta\Reservation $reservation
* @param array $new_data
* @return Model\Venta\Reservation
* @throws Common\Implement\Exception\EmptyResult
*/
protected function fetchBroker(Model\Venta\Reservation &$reservation, array $new_data): Model\Venta\Reservation
{
if (!array_key_exists('broker_id', $new_data)) {
$query = $this->connection->getQueryBuilder()
->select('reference_id')
->from('reservation_details')
->where('reservation_id = :id AND type = :type');
try {
$statement =$this->connection->execute($query, [
'id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Broker->value
]);
$result = $statement->fetch(PDO::FETCH_ASSOC);
if ($result === false) {
throw new Common\Implement\Exception\EmptyResult($query);
}
$reservation->broker = $this->brokerRepository->fetchById($result['reference_id']);
} catch (PDOException) {}
return $reservation;
}
try {
$reservation->broker = $this->brokerRepository->fetchById($new_data['broker_id']);
} catch (Common\Implement\Exception\EmptyResult) {}
return $reservation;
}
protected function fetchPromotions(Model\Venta\Reservation &$reservation, array $new_data): Model\Venta\Reservation
{
$this->fetchSavedPromotions($reservation);
$this->fetchUnsavedPromotions($reservation, $new_data);
return $reservation;
}
protected function fetchSavedPromotions(Model\Venta\Reservation &$reservation): Model\Venta\Reservation
{ {
$query = $this->connection->getQueryBuilder() $query = $this->connection->getQueryBuilder()
->select() ->select()
->from('reservation_details') ->from('reservation_data')
->where('type = :type AND reservation_id = :id'); ->where('type = "Promotion" AND reservation_id = :id');
$statement = $this->connection->execute($query, $statement = $this->connection->execute($query, ['id' => $reservation->id]);
['id' => $reservation->id, 'type' => Model\Venta\Reservation\Detail\Type::Promotion->value]);
while ($result = $statement->fetch(PDO::FETCH_ASSOC)) { while ($result = $statement->fetch(PDO::FETCH_ASSOC)) {
try { try {
$reservation->promotions []= $this->promotionRepository->fetchById($result['reference_id']); $reservation->promotions []= $this->promotionRepository->fetchById($result['reference_id']);
@ -542,43 +227,4 @@ class Reservation extends Common\Ideal\Repository
} }
return $reservation; return $reservation;
} }
protected function fetchUnsavedPromotions(Model\Venta\Reservation &$reservation, array $new_data): Model\Venta\Reservation
{
if (!array_key_exists('promotions', $new_data) or count($new_data['promotions']) > 0) {
return $reservation;
}
$queryCheck = $this->connection->getQueryBuilder()
->select('COUNT(id) AS cnt')
->from('reservation_details')
->where('type = :type AND reservation_id = :id AND reference_id = :promotion_id');
$statementCheck = $this->connection->prepare($queryCheck);
foreach ($new_data['promotions'] as $promotion) {
$statementCheck->execute([
'id' => $reservation->id,
'promotion_id' => $promotion
]);
$result = $statementCheck->fetch(PDO::FETCH_ASSOC);
if ($result['cnt'] > 0) {
continue;
}
try {
$reservation->promotions []= $this->promotionRepository->fetchById($promotion);
} catch (Common\Implement\Exception\EmptyResult) {}
}
return $reservation;
}
protected function removeBroker(Model\Venta\Reservation &$reservation): void
{
try {
$query = $this->connection->getQueryBuilder()
->delete()
->from('reservation_details')
->where('reservation_id = :id AND type = :type');
$this->connection->execute($query, [
'id' => $reservation->id,
'type' => Model\Venta\Reservation\Detail\Type::Broker->value
]);
$reservation->broker = null;
} catch (PDOException) {}
}
} }

View File

@ -7,8 +7,7 @@ use Incoviba\Repository;
class State extends Common\Ideal\Repository class State extends Common\Ideal\Repository
{ {
public function __construct(Common\Define\Connection $connection, public function __construct(Common\Define\Connection $connection, protected Repository\Venta\Reservation $reservationRepository)
protected Repository\Venta\Reservation $reservationRepository)
{ {
parent::__construct($connection); parent::__construct($connection);
} }
@ -20,16 +19,12 @@ class State extends Common\Ideal\Repository
public function create(?array $data = null): Model\Venta\Reservation\State public function create(?array $data = null): Model\Venta\Reservation\State
{ {
$map = (new Common\Implement\Repository\MapperParser()) $map = (new Common\Implement\Repository\MapperParser(['type']))
->register('reservation_id', (new Common\Implement\Repository\Mapper()) ->register('reservation_id', (new Common\Implement\Repository\Mapper())
->setProperty('reservation') ->setProperty('reservation')
->setFunction(function($data) { ->setFunction(function($data) use ($data) {
return $this->reservationRepository->fetchById($data['reservation_id']); return $this->reservationRepository->fetchById($data['reservation_id']);
})) }))
->register('type', (new Common\Implement\Repository\Mapper())
->setFunction(function($data) {
return Model\Venta\Reservation\State\Type::from($data['type']);
}))
->register('date', new Common\Implement\Repository\Mapper\DateTime('date')); ->register('date', new Common\Implement\Repository\Mapper\DateTime('date'));
return $this->parseData(new Model\Venta\Reservation\State(), $data, $map); return $this->parseData(new Model\Venta\Reservation\State(), $data, $map);
} }
@ -37,7 +32,7 @@ class State extends Common\Ideal\Repository
{ {
$model->id = $this->saveNew( $model->id = $this->saveNew(
['reservation_id', 'date', 'type'], ['reservation_id', 'date', 'type'],
[$model->reservation->id, $model->date->format('Y-m-d'), $model->type->value] [$model->reservation->id, $model->date->format('Y-m-d'), $model->type]
); );
return $model; return $model;
} }

View File

@ -4,7 +4,6 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal; use Incoviba\Common\Ideal;
use Incoviba\Common\Define; use Incoviba\Common\Define;
use Incoviba\Common\Implement; use Incoviba\Common\Implement;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model; use Incoviba\Model;
class TipoEstadoPrecio extends Ideal\Repository class TipoEstadoPrecio extends Ideal\Repository
@ -32,18 +31,4 @@ class TipoEstadoPrecio extends Ideal\Repository
{ {
return $this->update($model, ['descripcion'], $new_data); return $this->update($model, ['descripcion'], $new_data);
} }
/**
* @param string $descripcion
* @return Model\Venta\TipoEstadoPrecio
* @throws EmptyResult
*/
public function fetchByDescripcion(string $descripcion): Model\Venta\TipoEstadoPrecio
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('descripcion = ?');
return $this->fetchOne($query, [$descripcion]);
}
} }

View File

@ -1,49 +0,0 @@
<?php
namespace Incoviba\Service;
use PDOException;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Exception\ServiceAction;
use Incoviba\Model;
use Incoviba\Repository;
class Direccion extends Ideal\Service
{
public function __construct(LoggerInterface $logger, protected Repository\Direccion $direccionRepository)
{
parent::__construct($logger);
}
/**
* @param array $data
* @return Model\Direccion
* @throws ServiceAction\Create
*/
public function add(array $data): Model\Direccion
{
$dataMap = [
'street' => 'calle',
'number' => 'numero',
'comuna_id' => 'comuna',
];
foreach ($data as $key => $value) {
if (array_key_exists($key, $dataMap)) {
$data[$dataMap[$key]] = $value;
unset($data[$key]);
}
}
try {
return $this->direccionRepository->fetchByCalleAndNumeroAndExtraAndComuna($data['calle'], $data['numero'], $data['extra'], $data['comuna']);
} catch (Implement\Exception\EmptyResult) {
$filteredData = $this->direccionRepository->filterData($data);
$direccion = $this->direccionRepository->create($filteredData);
try {
return $this->direccionRepository->save($direccion);
} catch (PDOException $exception) {
throw new ServiceAction\Create(__CLASS__, $exception);
}
}
}
}

View File

@ -1,59 +0,0 @@
<?php
namespace Incoviba\Service;
use InvalidArgumentException;
use Psr\Http\Message\UploadedFileInterface;
use Incoviba\Common\Ideal;
use Incoviba\Exception\ServiceAction;
use Incoviba\Service\FileUpload\FileUploadInterface;
class FileUpload extends Ideal\Service implements FileUploadInterface
{
protected array $uploads = [];
public function register(FileUploadInterface $fileUpload, string $filetype = 'default'): self
{
$this->uploads [$filetype]= $fileUpload;
return $this;
}
/**
* @param UploadedFileInterface $uploadedFile
* @return array
* @throws ServiceAction\Read
*/
public function getData(UploadedFileInterface $uploadedFile): array
{
try {
$type = $this->getFileType($uploadedFile);
} catch (InvalidArgumentException $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
$uploader = $this->getUploader($type);
return $uploader->getData($uploadedFile);
}
/**
* @param UploadedFileInterface $uploadedFile
* @return string|null
*/
protected function getFileType(UploadedFileInterface $uploadedFile): ?string
{
$fileType = $uploadedFile->getClientMediaType();
$typesMap = [
'text/csv' => 'csv',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
'application/vnd.ms-excel' => 'xls',
];
if (!array_key_exists($fileType, $typesMap)) {
throw new InvalidArgumentException("File type {$fileType} not supported.");
}
return $typesMap[$fileType];
}
protected function getUploader(string $type): FileUploadInterface
{
if (!array_key_exists($type, $this->uploads)) {
return $this->uploads['default'];
}
return $this->uploads[$type];
}
}

View File

@ -1,147 +0,0 @@
<?php
namespace Incoviba\Service\FileUpload;
use InvalidArgumentException;
use OutOfBoundsException;
use Psr\Http\Message\UploadedFileInterface;
use PhpOffice\PhpSpreadsheet;
use Incoviba\Common\Ideal;
use Incoviba\Exception\ServiceAction\Read;
class ExcelBase extends Ideal\Service implements FileUploadInterface
{
/**
* @param UploadedFileInterface $uploadedFile
* @return array
* @throws Read
*/
public function getData(UploadedFileInterface $uploadedFile): array
{
$tempFilename = $this->createTempFile($uploadedFile);
$reader = PhpSpreadsheet\IOFactory::createReaderForFile($tempFilename);
$reader->setReadDataOnly(true);
$workbook = $reader->load($tempFilename);
try {
$sheet = $this->findSheet($workbook);
} catch (OutOfBoundsException $exception) {
throw new Read(__CLASS__, $exception);
}
$titles = $this->extractTitles($sheet);
$data = $this->extractData($sheet, $titles);
unlink($tempFilename);
return $data;
}
/**
* @param PhpSpreadsheet\Spreadsheet $workbook
* @return PhpSpreadsheet\Worksheet\Worksheet
* @throws OutOfBoundsException
*/
protected function findSheet(PhpSpreadsheet\Spreadsheet $workbook): PhpSpreadsheet\Worksheet\Worksheet
{
$sheet = $workbook->getActiveSheet();
if ($this->findTable($sheet)) {
return $sheet;
}
$sheets = $workbook->getAllSheets();
foreach ($sheets as $sheet) {
if ($this->findTable($sheet)) {
return $sheet;
}
}
throw new OutOfBoundsException('No table found in the workbook.');
}
protected function findTable(PhpSpreadsheet\Worksheet\Worksheet $sheet): bool
{
$rowIterator = $sheet->getRowIterator();
foreach ($rowIterator as $row) {
if ($row->isEmpty()) {
continue;
}
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
if ($cellIterator->valid()) {
return true;
}
foreach ($cellIterator as $cell) {
if ($cell->getCalculatedValue() !== '') {
return true;
}
}
}
return false;
}
protected function createTempFile(UploadedFileInterface $uploadedFile): string
{
$filename = $uploadedFile->getClientFilename();
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$tempFilename = tempnam(sys_get_temp_dir(), $extension);
$uploadedFile->moveTo($tempFilename);
return $tempFilename;
}
protected function extractTitles(PhpSpreadsheet\Worksheet\Worksheet $sheet): array
{
$titles = [];
$iterator = $sheet->getRowIterator();
foreach ($iterator as $row) {
if ($row->isEmpty()) {
continue;
}
$titles = $this->getRowData($row);
break;
}
return $titles;
}
protected function extractData(PhpSpreadsheet\Worksheet\Worksheet $sheet, array $titles): array
{
$data = [];
$rowIterator = $sheet->getRowIterator();
foreach ($rowIterator as $row) {
if ($row->isEmpty()) {
continue;
}
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
if ($cellIterator->current() === $titles[0]) {
continue;
}
try {
$rowData = $this->getRowData($row, $titles);
} catch (InvalidArgumentException $exception) {
if ($exception->getCode() === 1000) {
continue;
}
throw $exception;
}
$data []= array_combine($titles, $rowData);
}
return $data;
}
protected function getRowData(PhpSpreadsheet\Worksheet\Row $row, ?array $titles = null): array
{
$data = [];
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
foreach ($cellIterator as $cell) {
if ($cell->getCalculatedValue() === null) {
continue;
}
$value = $cell->getCalculatedValue();
if ($value === null) {
continue;
}
$value = mb_strtolower($value);
if ($titles !== null and in_array($value, $titles)) {
throw new InvalidArgumentException('Row matches title', 1000);
}
$data []= $value;
}
return $data;
}
}

View File

@ -1,9 +0,0 @@
<?php
namespace Incoviba\Service\FileUpload;
use Psr\Http\Message\UploadedFileInterface;
interface FileUploadInterface
{
public function getData(UploadedFileInterface $uploadedFile): array;
}

View File

@ -1,135 +1,149 @@
<?php <?php
namespace Incoviba\Service; namespace Incoviba\Service;
use DateInvalidTimeZoneException;
use DateMalformedStringException;
use DateTimeImmutable; use DateTimeImmutable;
use DateTimeZone; use DateTimeZone;
use InvalidArgumentException;
use OutOfRangeException;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Predis\Connection\ConnectionException;
use Incoviba\Common\Ideal; use Incoviba\Common\Ideal;
use Incoviba\Exception\MQTT as MQTTException; use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Exception\ServiceAction\{Create, Delete, Read, Update}; use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model; use Incoviba\Exception\ServiceAction\{Create, Read, Update};
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Model;
class Job extends Ideal\Service class Job extends Ideal\Service
{ {
public function __construct(LoggerInterface $logger, protected MQTT $mqttService, public function __construct(LoggerInterface $logger, protected Redis $redisService,
protected Repository\Job $jobRepository) protected Repository\Job $jobRepository)
{ {
parent::__construct($logger); parent::__construct($logger);
} }
protected string $redisKey = 'jobs';
public function isPending(): bool public function getPending(null|string|array $orderBy = null): array
{ {
try { try {
return $this->mqttService->exists(); $jobs = $this->redisService->get($this->redisKey);
} catch (MQTTException $exception) { if ($jobs === null) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]); return [];
return false; }
$jobs = json_decode($jobs, true);
if ($orderBy !== null) {
uksort($jobs, function($a, $b) use ($orderBy) {
return $a[$orderBy] <=> $b[$orderBy];
});
}
return array_map([$this, 'load'], $jobs);
} catch (ConnectionException | EmptyRedis) {
return [];
} }
} }
/** /**
* @param int $id
* @return Model\Job * @return Model\Job
* @throws Read * @throws Read
*/ */
public function get(): Model\Job public function getPendingById(int $id): Model\Job
{ {
$jobs = $this->getJobs();
try { try {
return $this->load(json_decode($this->mqttService->get(), true)); $idx = $this->findJob($jobs, $id);
} catch (MQTTException $exception) { } catch (EmptyResult $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]); $exception = new OutOfRangeException('Job not found', count($jobs), $exception);
throw new Read(__CLASS__, $exception); throw new Read(__CLASS__, $exception);
} }
return $this->load($jobs[$idx]);
} }
/** /**
* @param array $configuration * @param array $configuration
* @return Model\Job * @return Model\Job
* @throws Create * @throws Read
*/ */
public function add(array $configuration): Model\Job public function add(array $configuration): Model\Job
{ {
try { $now = (new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago')));
$now = (new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago')));
} catch (DateMalformedStringException | DateInvalidTimeZoneException $exception) {
$this->logger->warning($exception->getMessage(), ['exception' => $exception]);
$now = new DateTimeImmutable();
}
$data = [ $data = [
'id' => $now->format('Uu'), 'id' => $now->format('Uu'),
'configuration' => $configuration, 'configuration' => $configuration,
'executed' => false, 'executed' => false,
'created_at' => $now->format('Y-m-d H:i:s'), 'created_at' => $now->format('Y-m-d H:i:s'),
'updated_at' => null, 'updated_at' => null
'retries' => 0
]; ];
$jobs = [];
try { try {
$this->mqttService->set(json_encode($data)); $jobs = $this->redisService->get($this->redisKey);
} catch (MQTTException $exception) { if ($jobs !== null) {
throw new Create(__CLASS__, $exception); $jobs = json_decode($jobs, true);
} }
} catch (EmptyRedis) {}
$jobs []= $data;
$this->redisService->set($this->redisKey, json_encode($jobs), -1);
return $this->load($data); return $this->load($data);
} }
/**
* @param Model\Job $job
* @return void
* @throws Update
*/
public function update(Model\Job $job): void
{
try {
$now = (new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago')));
} catch (DateMalformedStringException | DateInvalidTimeZoneException) {
$now = new DateTimeImmutable();
}
$data = json_decode(json_encode($job), true);
$data['updated_at'] = $now->format('Y-m-d H:i:s');
try {
$this->mqttService->update(json_encode($data));
} catch (MQTTException $exception) {
throw new Update(__CLASS__, $exception);
}
}
/**
* @param Model\Job $job
* @throws Delete
*/
public function remove(Model\Job $job): void
{
try {
$this->mqttService->remove();
} catch (MQTTException $exception) {
throw new Delete(__CLASS__, $exception);
}
}
/** /**
* @param Model\Job $job * @param Model\Job $job
* @return bool * @return bool
* @throws Read
*/ */
public function execute(Model\Job $job): bool public function execute(Model\Job $job): bool
{ {
$jobs = $this->getJobs();
try { try {
$this->mqttService->remove(); $idx = $this->findJob($jobs, $job->id);
return true; } catch (EmptyResult $exception) {
} catch (MQTTException $exception) { $exception = new OutOfRangeException('Job not found', count($jobs), $exception);
$this->logger->error($exception->getMessage(), ['exception' => $exception]); throw new Read(__CLASS__, $exception);
return false;
} }
unset($jobs[$idx]);
$this->redisService->set($this->redisKey, json_encode(array_values($jobs)), -1);
return true;
} }
/**
* @return array
* @throws Read
*/
protected function getJobs(): array
{
try {
$jobs = $this->redisService->get($this->redisKey);
} catch (EmptyRedis $exception) {
throw new Read(__CLASS__, $exception);
}
if ($jobs === null) {
$exception = new InvalidArgumentException("Redis Key {$this->redisKey} not found");
throw new Read(__CLASS__, $exception);
}
return json_decode($jobs, true);
}
/**
* @param array $jobs
* @param int $id
* @return int
* @throws EmptyResult
*/
protected function findJob(array $jobs, int $id): int
{
$idx = array_find_key($jobs, function($job) use ($id) {
return (int) $job['id'] === $id;
});
if ($idx === null) {
throw new EmptyResult("SELECT * FROM jobs WHERE id = ?");
}
return $idx;
}
protected function load(array $data, ?int $id = null): Model\Job protected function load(array $data, ?int $id = null): Model\Job
{ {
$job = new Model\Job(); $job = new Model\Job();
$job->id = $id ?? $data['id'] ?? null; $job->id = $id ?? $data['id'] ?? null;
$job->configuration = $data['configuration'] ?? []; $job->configuration = $data['configuration'] ?? [];
$job->executed = $data['executed'] ?? false; $job->executed = $data['executed'] ?? false;
$job->retries = $data['retries'] ?? 0;
return $job; return $job;
} }
} }

View File

@ -167,13 +167,8 @@ class Login
try { try {
$login = $this->repository->fetchActiveByUser($user->id); $login = $this->repository->fetchActiveByUser($user->id);
$this->logout($login->user); $this->logout($login->user);
} catch (EmptyResult $exception) { } catch (PDOException | EmptyResult $exception) {
$message []= "No logins for user {$user->name}"; error_log($exception, 3, '/logs/exception.log');
$message []= $exception->getMessage();
$message []= $exception->getTraceAsString();
error_log(implode(PHP_EOL, $message).PHP_EOL, 3, '/logs/login-exception.log');
} catch (PDOException $exception) {
error_log($exception.PHP_EOL, 3, '/logs/login-exception.log');
} }
try { try {
@ -190,7 +185,7 @@ class Login
$this->saveCookie($selector, $token, $login->dateTime->add(new DateInterval("PT{$this->max_login_time}H"))); $this->saveCookie($selector, $token, $login->dateTime->add(new DateInterval("PT{$this->max_login_time}H")));
return true; return true;
} catch (PDOException | Exception $exception) { } catch (PDOException | Exception $exception) {
error_log($exception.PHP_EOL, 3, '/logs/login-exception.log'); error_log($exception, 3, '/logs/exception.log');
return false; return false;
} }
} }

View File

@ -1,102 +0,0 @@
<?php
namespace Incoviba\Service;
use Incoviba\Exception\MQTT as MQTTException;
use Incoviba\Service\MQTT\MQTTInterface;
class MQTT implements MQTTInterface
{
protected array $clients = [];
public function register(string $name, MQTTInterface $client): self
{
$this->clients[$name] = $client;
return $this;
}
public function clientExists(string $name): bool
{
return isset($this->clients[$name]);
}
/**
* @param string|null $name
* @return MQTTInterface
* @throws MQTTException/MissingClient
*/
public function getClient(?string $name = null): MQTTInterface
{
if ($name === null) {
$name = array_keys($this->clients)[0];
}
if (!$this->clientExists($name)) {
throw new MQTTException\MissingClient($name);
}
return $this->clients[$name];
}
/**
* @param string|null $host
* @return bool
* @throws MQTTException/MissingClient
* @throws MQTTException/MissingJob
*/
public function exists(?string $host = null): bool
{
$client = $this->getClient($host);
return $client->exists();
}
/**
* @param string|null $host
* @return string
* @throws MQTTException/MissingClient
* @throws MQTTException/MissingJob
*/
public function get(?string $host = null): string
{
$client = $this->getClient($host);
return $client->get();
}
/**
* @param string $value
* @param int $delay
* @param string|null $host
* @return $this
* @throws MQTTException/MissingClient
* @throws MQTTException/SetJob
*/
public function set(string $value, int $delay = 0, ?string $host = null): self
{
$client = $this->getClient($host);
$client->set($value, $delay);
return $this;
}
/**
* @param int|null $jobId
* @param string|null $host
* @return $this
* @throws MQTTException/MissingJob
* @throws MQTTException/RemoveJob
*/
public function remove(?int $jobId = null, ?string $host = null): self
{
$this->getClient($host)->remove($jobId);
return $this;
}
/**
* @param string $newPayload
* @param int|null $jobId
* @param string|null $host
* @return $this
* @throws MQTTException/MissingJob
* @throws MQTTException/RemoveJob
* @throws MQTTException/SetJob
*/
public function update(string $newPayload, ?int $jobId = null, ?string $host = null): self
{
$this->getClient($host)->update($newPayload, $jobId);
return $this;
}
}

View File

@ -1,111 +0,0 @@
<?php
namespace Incoviba\Service\MQTT;
use Exception;
use Incoviba\Exception\MQTT\MissingJob;
use Incoviba\Exception\MQTT\RemoveJob;
use Incoviba\Exception\MQTT\SetJob;
use Psr\Log\LoggerInterface;
use xobotyi\beansclient;
use xobotyi\beansclient\Exception\ClientException;
use xobotyi\beansclient\Exception\CommandException;
use xobotyi\beansclient\Exception\JobException;
class Beanstalkd implements MQTTInterface
{
/**
* @throws JobException
* @throws ClientException
* @throws CommandException
*/
public function __construct(protected LoggerInterface $logger, protected beansclient\BeansClient $client,
protected string $tube = 'default', protected int $ttr = beansclient\BeansClient::DEFAULT_TTR,
protected int $priority = 1)
{
$this->client->watchTube($this->tube);
}
public function exists(): bool
{
try {
$stats = $this->client->statsTube($this->tube);
return $stats['current-jobs-ready'] > 0;
} catch (Exception $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
return false;
}
}
protected ?beansclient\Job $currentJob = null;
public function get(): string
{
if (!$this->exists()) {
throw new MissingJob();
}
try {
$job = $this->client->watchTube($this->tube)->reserve();
$this->currentJob = $job;
return $job->payload;
} catch (Exception $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
throw new MissingJob($exception);
}
}
/**
* @param string $value
* @param int $delay
* @return $this
* @throws SetJob
*/
public function set(string $value, int $delay = 0): self
{
try {
$this->client->useTube($this->tube)->put($value, $this->priority, $delay, $this->ttr ?? 0);
} catch (Exception $exception) {
$this->logger->error($exception->getMessage(), ['payload' => $value, 'delay' => $delay, 'exception' => $exception]);
throw new SetJob($value, $exception);
}
return $this;
}
/**
* @param string $newPayload
* @param int|null $jobId
* @return self
* @throws RemoveJob
* @throws SetJob
*/
public function update(string $newPayload, ?int $jobId = null): self
{
if ($jobId === null) {
$jobId = $this->currentJob->id;
}
return $this->remove($jobId)
->set($newPayload);
}
/**
* @param int|null $jobId
* @return $this
* @throws RemoveJob
*/
public function remove(?int $jobId = null): self
{
if ($jobId === null) {
$jobId = $this->currentJob->id;
}
try {
if (!$this->client->useTube($this->tube)->delete($jobId)) {
throw new JobException("Failed to delete job {$jobId}");
}
if ($this->currentJob !== null && $this->currentJob->id === $jobId) {
$this->currentJob = null;
}
} catch (Exception $exception) {
$this->logger->error($exception->getMessage(), ['jobId' => $jobId, 'exception' => $exception]);
throw new RemoveJob($jobId, $exception);
}
return $this;
}
}

View File

@ -1,25 +0,0 @@
<?php
namespace Incoviba\Service\MQTT;
use Incoviba\Exception\MQTT\MissingJob;
interface MQTTInterface {
/**
* @return bool
*/
public function exists(): bool;
/**
* @return string
* @throws MissingJob
*/
public function get(): string;
/**
* @param string $value
* @param int $delay
* @return self
*/
public function set(string $value, int $delay = 0): self;
public function remove(?int $jobId = null): self;
}

View File

@ -1,59 +0,0 @@
<?php
namespace Incoviba\Service\MQTT;
use Incoviba\Common\Ideal\Service;
use Psr\Log\LoggerInterface;
use Pheanstalk as PBA;
class Pheanstalk extends Service implements MQTTInterface
{
const string DEFAULT_TUBE = 'default';
const int DEFAULT_TTR = 60;
const int DEFAULT_PRIORITY = 1_024;
public function __construct(LoggerInterface $logger, protected PBA\Pheanstalk $client, string $tubeName = self::DEFAULT_TUBE)
{
parent::__construct($logger);
$this->tube = new PBA\Values\TubeName($tubeName);
}
protected PBA\Values\TubeName $tube;
public function set(string $value, int $delay = 0): self
{
$this->client->useTube($this->tube);
$this->client->put($value, self::DEFAULT_PRIORITY, $delay, self::DEFAULT_TTR);
return $this;
}
public function exists(): bool
{
$stats = $this->client->statsTube($this->tube);
return $stats->currentJobsReady > 0;
}
protected int $currentJobId;
public function get(): string
{
$this->client->useTube($this->tube);
$job = $this->client->reserve();
$this->currentJobId = $job->getId();
return $job->getData();
}
public function update(string $newPayload, ?int $jobId = null): self
{
if ($jobId === null) {
$jobId = $this->currentJobId;
}
$this->remove($jobId);
$this->set($newPayload);
return $this;
}
public function remove(?int $jobId = null): self
{
if ($jobId === null) {
$jobId = $this->currentJobId;
}
$this->client->useTube($this->tube);
$this->client->delete(new PBA\Values\JobId($jobId));
return $this;
}
}

View File

@ -15,8 +15,7 @@ class Persona extends Ideal\Service
public function __construct(LoggerInterface $logger, public function __construct(LoggerInterface $logger,
protected Repository\Persona $personaRepository, protected Repository\Persona $personaRepository,
protected Repository\Persona\Datos $datosPersonaRepository, protected Repository\Persona\Datos $datosPersonaRepository,
protected Repository\Venta\Propietario $propietarioRepository, protected Repository\Venta\Propietario $propietarioRepository)
protected Direccion $direccionService)
{ {
parent::__construct($logger); parent::__construct($logger);
} }
@ -36,7 +35,7 @@ class Persona extends Ideal\Service
/** /**
* @param int $rut * @param int $rut
* @return Model\Persona * @return Model\Persona
* @throws Read * @throws Read|Create
*/ */
public function getById(int $rut): Model\Persona public function getById(int $rut): Model\Persona
{ {
@ -45,11 +44,7 @@ class Persona extends Ideal\Service
} catch (Implement\Exception\EmptyResult) { } catch (Implement\Exception\EmptyResult) {
try { try {
$this->propietarioRepository->fetchById($rut); $this->propietarioRepository->fetchById($rut);
try { return $this->add(compact('rut'));
return $this->add(compact('rut'));
} catch (Create $exception) {
throw new Read(__CLASS__, $exception);
}
} catch (Implement\Exception\EmptyResult $exception) { } catch (Implement\Exception\EmptyResult $exception) {
throw new Read(__CLASS__, $exception); throw new Read(__CLASS__, $exception);
} }
@ -68,34 +63,44 @@ class Persona extends Ideal\Service
} catch (Implement\Exception\EmptyResult) { } catch (Implement\Exception\EmptyResult) {
try { try {
$propietario = $this->propietarioRepository->fetchById($data['rut']); $propietario = $this->propietarioRepository->fetchById($data['rut']);
$persona = $this->addFromPropietario($propietario); } catch (Implement\Exception\EmptyResult $exception) {
throw new Create(__CLASS__, $exception);
}
$data['rut'] = $propietario->rut;
$data['digito'] = $propietario->dv;
$data['nombres'] = $propietario->nombres;
$data['apellido_paterno'] = $propietario->apellidos['paterno'];
$data['apellido_materno'] = $propietario->apellidos['materno'] ?? '';
$persona = $this->personaRepository->create($data);
try {
$persona = $this->personaRepository->save($persona);
} catch (PDOException $exception) {
throw new Create(__CLASS__, $exception);
}
}
if (isset($data['direccion_id']) or isset($data['email']) or isset($data['telefono'])) {
$datosData = ['persona_rut' => $persona->rut];
if (isset($data['direccion_id'])) {
$datosData['direccion_id'] = $data['direccion_id'];
}
if (isset($data['email'])) {
$datosData['email'] = $data['email'];
}
if (isset($data['telefono'])) {
$datosData['telefono'] = $data['telefono'];
}
try {
$datos = $this->datosPersonaRepository->fetchByPersona($persona->rut);
$this->datosPersonaRepository->edit($datos, $data);
} catch (Implement\Exception\EmptyResult) { } catch (Implement\Exception\EmptyResult) {
$dataMap = [ $datos = $this->datosPersonaRepository->create($datosData);
'digit' => 'digito',
'name' => 'nombres',
'names' => 'nombres',
'last_name' => 'apellido_paterno',
'last_name2' => 'apellido_materno',
];
foreach ($data as $key => $value) {
if (array_key_exists($key, $dataMap)) {
$data[$dataMap[$key]] = $value;
unset($data[$key]);
}
}
$filteredData = $this->personaRepository->filterData($data);
try { try {
$persona = $this->personaRepository->create($filteredData); $this->datosPersonaRepository->save($datos);
$persona = $this->personaRepository->save($persona);
} catch (PDOException $exception) { } catch (PDOException $exception) {
throw new Create(__CLASS__, $exception); throw new Create(__CLASS__, $exception);
} }
} }
} }
$this->addDatos($persona, $data);
return $this->process($persona); return $this->process($persona);
} }
@ -171,113 +176,4 @@ class Persona extends Ideal\Service
->setArgs(['persona_rut' => $persona->rut])); ->setArgs(['persona_rut' => $persona->rut]));
return $persona; return $persona;
} }
/**
* @param Model\Venta\Propietario $propietario
* @return Model\Persona
* @throws Create
*/
protected function addFromPropietario(Model\Venta\Propietario $propietario): Model\Persona
{
$data = [
'rut' => $propietario->rut,
'digito' => $propietario->dv,
'nombres' => $propietario->nombres,
'apellido_paterno' => $propietario->apellidos['paterno'],
'apellido_materno' => $propietario->apellidos['materno'] ?? '',
];
try {
$persona = $this->personaRepository->create($data);
$persona = $this->personaRepository->save($persona);
} catch (PDOException $exception) {
throw new Create(__CLASS__, $exception);
}
$datosData = [];
if ($propietario->datos->direccion) {
$datosData['direccion_id'] = $propietario->datos?->direccion->id;
}
if ($propietario->datos->email) {
$datosData['email'] = $propietario->datos->email;
}
if ($propietario->datos->telefono) {
$datosData['telefono'] = $propietario->datos->telefono;
}
if ($propietario->datos->estado_civil) {
$datosData['estado_civil'] = $propietario->datos->estado_civil;
}
if ($propietario->datos->fecha_nacimiento) {
$datosData['fecha_nacimiento'] = $propietario->datos->fecha_nacimiento;
}
if ($propietario->datos->profesion) {
$datosData['ocupacion'] = $propietario->datos->profesion;
}
if ($propietario->datos->sexo) {
$datosData['sexo'] = $propietario->datos->sexo;
}
$this->addDatos($persona, $datosData);
return $persona;
}
/**
* @param Model\Persona $persona
* @param array $data
* @return Model\Persona
* @throws Create
*/
protected function addDatos(Model\Persona $persona, array $data): Model\Persona
{
$addressData = [];
foreach ($data as $key => $value) {
if (!str_starts_with($key, 'address_') and !str_starts_with($key, 'direccion_')) {
continue;
}
if (str_starts_with($key, 'direccion_')) {
$newKey = substr($key, strlen('direccion_'));
} else {
$newKey = substr($key, strlen('address_'));
}
$addressData[$newKey] = $value;
}
if (!empty($addressData)) {
$address = $this->direccionService->add($addressData);
foreach ($data as $key => $value) {
if (str_starts_with($key, 'address_') or str_starts_with($key, 'direccion_')) {
unset($data[$key]);
}
}
$data['direccion_id'] = $address->id;
}
$dataMap = [
'phone' => 'telefono',
'profession' => 'ocupacion',
'profesion' => 'ocupacion',
'sex' => 'sexo',
'marital_status' => 'estado_civil',
'birth_date' => 'fecha_nacimiento',
'birthdate' => 'fecha_nacimiento',
];
foreach ($data as $key => $value) {
if (array_key_exists($key, $dataMap)) {
$data[$dataMap[$key]] = $value;
unset($data[$key]);
}
}
try {
$datos = $this->datosPersonaRepository->fetchByPersona($persona->rut);
$this->datosPersonaRepository->edit($datos, $data);
} catch (Implement\Exception\EmptyResult $exception) {
$datosData = ['persona_rut' => $persona->rut, ...$data];
$datosData = $this->datosPersonaRepository->filterData($datosData);
$datos = $this->datosPersonaRepository->create($datosData);
try {
$this->datosPersonaRepository->save($datos);
} catch (PDOException $exception) {
throw new Create(__CLASS__, $exception);
}
}
return $persona;
}
} }

View File

@ -5,14 +5,12 @@ use Exception;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal; use Incoviba\Common\Ideal;
use Incoviba\Exception\ServiceAction\{Create, Delete, Read, Update}; use Incoviba\Exception\ServiceAction\{Create, Read};
use Incoviba\Service; use Incoviba\Service;
use Incoviba\Model;
class Queue extends Ideal\Service class Queue extends Ideal\Service
{ {
public function __construct(LoggerInterface $logger, protected Service\Job $jobService, Worker $defaultWorker, public function __construct(LoggerInterface $logger, protected Service\Job $jobService, Worker $defaultWorker)
protected int $maxRetries = 5)
{ {
parent::__construct($logger); parent::__construct($logger);
$this->register('default', $defaultWorker); $this->register('default', $defaultWorker);
@ -30,7 +28,7 @@ class Queue extends Ideal\Service
try { try {
$this->jobService->add($configuration); $this->jobService->add($configuration);
return true; return true;
} catch (Create $exception) { } catch (Read $exception) {
$final = new Exception("Could not enqueue job", 0, $exception); $final = new Exception("Could not enqueue job", 0, $exception);
$this->logger->warning($final); $this->logger->warning($final);
return false; return false;
@ -41,8 +39,22 @@ class Queue extends Ideal\Service
return $this->enqueue($configuration); return $this->enqueue($configuration);
} }
public function runJob(Model\Job $job, ?RequestInterface $request = null): bool /**
* @return array
*/
public function getPendingJobs(): array
{ {
return $this->jobService->getPending();
}
public function runJob(int $job_id, ?RequestInterface $request = null): bool
{
try {
$job = $this->jobService->getPendingById($job_id);
} catch (Read $exception) {
$this->logger->debug($exception);
return false;
}
$type = 'default'; $type = 'default';
if (isset($job->configuration['type'])) { if (isset($job->configuration['type'])) {
$type = strtolower($job->configuration['type']); $type = strtolower($job->configuration['type']);
@ -58,57 +70,36 @@ class Queue extends Ideal\Service
try { try {
if (!$worker->execute($job)) { if (!$worker->execute($job)) {
$this->logger->debug("Could not execute job {$job->id}"); $this->logger->debug("Could not execute job {$job_id}");
$job->retries++;
$this->jobService->update($job);
return false; return false;
} }
if (!$this->jobService->execute($job)) { if (!$this->jobService->execute($job)) {
$this->logger->debug("Could not remove job {$job->id}"); $this->logger->debug("Could not remove job {$job_id}");
return false; return false;
} }
} catch (Exception $exception) { } catch (Exception $exception) {
$this->logger->warning("Could not run job {$job->id}", ['exception' => $exception]); $final = new Exception("Could not run job", 0, $exception);
$job->retries++; $this->logger->warning($final);
try {
$this->jobService->update($job);
} catch (Update $exception) {
$this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => $exception]);
}
return false; return false;
} }
return true; return true;
} }
public function run(?RequestInterface $request = null): bool public function run(?RequestInterface $request = null): bool
{ {
if (!$this->jobService->isPending()) { $jobs = $this->jobService->getPending();
if (count($jobs) === 0) {
$this->logger->debug("No pending jobs");
return true; return true;
} }
try {
$job = $this->jobService->get(); $errors = [];
} catch (Read $exception) { foreach ($jobs as $job) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
return false;
}
if ($job->retries >= $this->maxRetries) {
try { try {
$this->jobService->remove($job); $this->runJob($job->id, $request);
} catch (Delete $exception) { } catch (Exception) {
$this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => $exception]); $errors []= $job->id;
} }
return true;
} }
try { return count($errors) === 0;
$this->runJob($job, $request);
} catch (Exception) {
$job->retries ++;
try {
$this->jobService->update($job);
} catch (Update $exception) {
$this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => $exception]);
}
return false;
}
return true;
} }
} }

View File

@ -4,7 +4,7 @@ namespace Incoviba\Service;
use DateTimeInterface; use DateTimeInterface;
use DateTimeImmutable; use DateTimeImmutable;
use DateMalformedStringException; use DateMalformedStringException;
use Incoviba\Service\Valor\Phone; use function PHPUnit\Framework\countOf;
class Valor class Valor
{ {
@ -40,14 +40,6 @@ class Valor
} }
return $value / $this->ufService->get($date); return $value / $this->ufService->get($date);
} }
public function phone(): Phone
{
return new Phone();
}
public function telefono(): Phone
{
return $this->phone();
}
protected function getDateTime(null|string|DateTimeInterface $date): DateTimeInterface protected function getDateTime(null|string|DateTimeInterface $date): DateTimeInterface
{ {

View File

@ -1,28 +0,0 @@
<?php
namespace Incoviba\Service\Valor;
class Phone
{
public function toDatabase(?string $phone): ?int
{
if ($phone === null) {
return null;
}
return (int) str_replace([' ', '+'], '', $phone) ?? null;
}
public function toDisplay(?int $phone): ?string
{
if ($phone === null) {
return null;
}
$parts = preg_split('/(?=<country>\d{2})?(?=<area>\d)(?=<first>\d{4})(?=<last>\d{4})/', $phone);
$output = [];
if (array_key_exists('country', $parts)) {
$output [] = "+{$parts[0]}";
}
$output [] = $parts[1] ?? '';
$output [] = $parts[2] ?? '';
$output [] = $parts[3] ?? '';
return implode(' ', $output);
}
}

View File

@ -1,10 +1,10 @@
<?php <?php
namespace Incoviba\Service; namespace Incoviba\Service;
use Exception;
use DateTimeImmutable; use DateTimeImmutable;
use DateMalformedStringException; use DateMalformedStringException;
use Incoviba\Exception\ServiceAction\{Create, Read, Update}; use Incoviba\Exception\ServiceAction\{Create, Read, Update};
use Incoviba\Common\Define;
use PDOException; use PDOException;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal\Service; use Incoviba\Common\Ideal\Service;
@ -12,7 +12,7 @@ use Incoviba\Common\Implement;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Model; use Incoviba\Model;
class Venta extends Service\Repository class Venta extends Service
{ {
public function __construct( public function __construct(
LoggerInterface $logger, LoggerInterface $logger,
@ -189,11 +189,6 @@ class Venta extends Service\Repository
} }
} }
public function getRepository(): Define\Repository
{
return $this->ventaRepository;
}
protected function process(Model\Venta $venta): Model\Venta protected function process(Model\Venta $venta): Model\Venta
{ {
if ($venta->uf === 0.0) { if ($venta->uf === 0.0) {

View File

@ -76,24 +76,15 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
* @param array $data * @param array $data
* @param array $validStatus * @param array $validStatus
* @param array $invalidStatus * @param array $invalidStatus
* @param string|null $accountKey
* @return bool * @return bool
* @throws EmptyResponse * @throws EmptyResponse
*/ */
protected function sendAdd(string $request_uri, array $data, array $validStatus, array $invalidStatus, ?string $accountKey = null): bool protected function sendAdd(string $request_uri, array $data, array $validStatus, array $invalidStatus): bool
{ {
$params = $this->mapParams($data); $params = $this->mapParams($data);
$this->logger->info('Send Add', ['uri' => $request_uri, 'params' => $params]); $this->logger->info('Send Add', ['uri' => $request_uri, 'params' => $params]);
try { try {
$options = [ $response = $this->client->post($request_uri, ['json' => $params]);
'json' => $params
];
if ($accountKey !== null) {
$options['headers'] = [
'X-Account-Key' => $accountKey
];
}
$response = $this->client->post($request_uri, $options);
} catch (ClientExceptionInterface $exception) { } catch (ClientExceptionInterface $exception) {
throw new EmptyResponse($request_uri, $exception); throw new EmptyResponse($request_uri, $exception);
} }
@ -120,23 +111,14 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
* @param array $data * @param array $data
* @param array $validStatus * @param array $validStatus
* @param array $invalidStatus * @param array $invalidStatus
* @param string|null $accountKey
* @return bool * @return bool
* @throws EmptyResponse * @throws EmptyResponse
*/ */
protected function sendEdit(string $request_uri, array $data, array $validStatus, array $invalidStatus, ?string $accountKey = null): bool protected function sendEdit(string $request_uri, array $data, array $validStatus, array $invalidStatus): bool
{ {
$params = $this->mapParams($data); $params = $this->mapParams($data);
try { try {
$options = [ $response = $this->client->put($request_uri, ['json' => $params]);
'json' => $params
];
if ($accountKey !== null) {
$options['headers'] = [
'X-Account-Key' => $accountKey
];
}
$response = $this->client->put($request_uri, $options);
} catch (ClientExceptionInterface $exception) { } catch (ClientExceptionInterface $exception) {
throw new EmptyResponse($request_uri, $exception); throw new EmptyResponse($request_uri, $exception);
} }

View File

@ -28,20 +28,18 @@ interface EndPoint
/** /**
* @param array $data * @param array $data
* @param string|null $accountKey
* @return bool * @return bool
* @throws EmptyResponse * @throws EmptyResponse
*/ */
public function add(array $data, ?string $accountKey = null): bool; public function add(array $data): bool;
/** /**
* @param string $id * @param string $id
* @param array $data * @param array $data
* @param string|null $accountKey
* @return bool * @return bool
* @throws EmptyResponse * @throws EmptyResponse
*/ */
public function edit(string $id, array $data, ?string $accountKey = null): bool; public function edit(string $id, array $data): bool;
/** /**
* @param string $id * @param string $id

View File

@ -1,10 +1,8 @@
<?php <?php
namespace Incoviba\Service\Venta\MediosPago; namespace Incoviba\Service\Venta\MediosPago;
use Incoviba\Common\Implement\Exception\EmptyResult;
use InvalidArgumentException; use InvalidArgumentException;
use PDO; use PDO;
use PDOException;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Define\Connection; use Incoviba\Common\Define\Connection;
use Incoviba\Common\Ideal; use Incoviba\Common\Ideal;
@ -82,18 +80,13 @@ class Toku extends Ideal\Service
try { try {
return $this->subscription->getById($venta->id); return $this->subscription->getById($venta->id);
} catch (InvalidResult $exception) { } catch (InvalidResult $exception) {
$inmobiliaria = $venta->proyecto()->inmobiliaria();
$accountKey = null;
try {
$accountKey = $this->getAccountKey($inmobiliaria->rut);
} catch (EmptyResult) {}
$subscriptionData = [ $subscriptionData = [
'customer' => $customer['toku_id'], 'customer' => $customer['toku_id'],
'product_id' => $venta->id, 'product_id' => $venta->id,
'venta' => $venta 'venta' => $venta
]; ];
try { try {
if (!$this->subscription->add($subscriptionData, $accountKey)) { if (!$this->subscription->add($subscriptionData)) {
throw new InvalidResult("Could not save Subscription for Venta {$venta->id}", 409, $exception); throw new InvalidResult("Could not save Subscription for Venta {$venta->id}", 409, $exception);
} }
} catch (EmptyResponse $exception) { } catch (EmptyResponse $exception) {
@ -102,6 +95,7 @@ class Toku extends Ideal\Service
return $this->subscription->getById($venta->id); return $this->subscription->getById($venta->id);
} }
} }
/** /**
* @param Model\Venta $venta * @param Model\Venta $venta
* @param array $cuotas_ids * @param array $cuotas_ids
@ -121,12 +115,6 @@ class Toku extends Ideal\Service
}); });
} catch (EmptyResponse) {} } catch (EmptyResponse) {}
$inmobiliaria = $venta->proyecto()->inmobiliaria();
$accountKey = null;
try {
$accountKey = $this->getAccountKey($inmobiliaria->rut);
} catch (EmptyResult) {}
$invoices = []; $invoices = [];
$errors = []; $errors = [];
foreach ($venta->formaPago()->pie->cuotas() as $cuota) { foreach ($venta->formaPago()->pie->cuotas() as $cuota) {
@ -154,7 +142,7 @@ class Toku extends Ideal\Service
'cuota' => $cuota, 'cuota' => $cuota,
'venta' => $venta 'venta' => $venta
]; ];
if (!$this->invoice->add($invoiceData, $accountKey)) { if (!$this->invoice->add($invoiceData)) {
throw new EmptyResponse("Could not add Invoice for Cuota {$cuota->id}", $exception); throw new EmptyResponse("Could not add Invoice for Cuota {$cuota->id}", $exception);
} }
$invoices []= $this->invoice->getById($cuota->id); $invoices []= $this->invoice->getById($cuota->id);
@ -302,95 +290,6 @@ class Toku extends Ideal\Service
return $queues; return $queues;
} }
public function update(array $ids, ?string $type = null): array
{
if ($type === null) {
$types = [
'customers',
'subscriptions',
'invoices'
];
$results = [];
foreach ($types as $type) {
$results[$type] = $this->update($ids[$type], $type);
}
return $results;
}
$results = [];
switch ($type) {
case 'subscriptions':
try {
$results['subscription'] = $this->subscription->update($ids);
} catch (EmptyResult | EmptyResponse $exception) {
$this->logger->error($exception);
}
break;
case 'invoices':
try {
$results['invoice'] = $this->invoice->updateAll($ids);
} catch (EmptyResult $exception) {
$this->logger->error($exception);
}
break;
}
return $results;
}
/**
* @param ServerRequestInterface $request
* @param array $tokenConfig
* @return bool
*/
public function validateToken(ServerRequestInterface $request, array $tokenConfig): bool
{
if (!$request->hasHeader('User-Agent') or !str_starts_with($request->getHeaderLine('User-Agent'), 'Toku-Webhooks')) {
return false;
}
if (!$request->hasHeader('X-Datadog-Tags') or !$request->hasHeader('Tracestate')) {
return false;
}
if (!$request->hasHeader('Toku-Signature')) {
return false;
}
$tokuSignature = $request->getHeaderLine('Toku-Signature');
try {
list($timestamp, $signature) = array_map(function($elem) {
return explode('=', $elem)[1];
}, explode(',', $tokuSignature));
$body = $request->getBody()->getContents();
$json = json_decode($body, true);
if (!is_array($json)) {
return false;
}
if (!array_key_exists('id', $json)) {
return false;
}
$eventId = $json['id'];
$eventType = $json['event_type'];
$query = $this->connection->getQueryBuilder()
->select('secret')
->from('toku_webhooks')
->where('enabled = ? AND JSON_SEARCH(events, "one", ?) IS NOT NULL');
$params = [true, $eventType];
$statement = $this->connection->prepare($query);
$statement->execute($params);
$results = $statement->fetchAll(PDO::FETCH_COLUMN);
if (count($results) === 0) {
return false;
}
if (array_any($results, fn($secret) => $this->hmac->validate($timestamp, $signature, $eventId, $secret))) {
return true;
}
} catch (Throwable $throwable) {
$this->logger->error($throwable);
}
return false;
}
/** /**
* @param array $request * @param array $request
* @return bool * @return bool
@ -507,20 +406,54 @@ class Toku extends Ideal\Service
$data['date'] = $data['transaction_date']; $data['date'] = $data['transaction_date'];
return $data; return $data;
} }
protected function getAccountKey(int $sociedad_rut): string
public function validateToken(ServerRequestInterface $request, array $tokenConfig): bool
{ {
$query = $this->connection->getQueryBuilder() if (!$request->hasHeader('User-Agent') or !str_starts_with($request->getHeaderLine('User-Agent'), 'Toku-Webhooks')) {
->select('account_key') return false;
->from('toku_accounts') }
->where('enabled = ? AND sociedad_rut = ?'); if (!$request->hasHeader('X-Datadog-Tags') or !$request->hasHeader('Tracestate')) {
$params = [true, $sociedad_rut]; return false;
}
if (!$request->hasHeader('Toku-Signature')) {
return false;
}
$tokuSignature = $request->getHeaderLine('Toku-Signature');
try { try {
list($timestamp, $signature) = array_map(function($elem) {
return explode('=', $elem)[1];
}, explode(',', $tokuSignature));
$body = $request->getBody()->getContents();
$json = json_decode($body, true);
if (!is_array($json)) {
return false;
}
if (!array_key_exists('id', $json)) {
return false;
}
$eventId = $json['id'];
$eventType = $json['event_type'];
$query = $this->connection->getQueryBuilder()
->select('secret')
->from('toku_webhooks')
->where('enabled = ? AND JSON_SEARCH(events, "one", ?) IS NOT NULL');
$params = [true, $eventType];
$statement = $this->connection->prepare($query); $statement = $this->connection->prepare($query);
$statement->execute($params); $statement->execute($params);
return $statement->fetchColumn(); $results = $statement->fetchAll(PDO::FETCH_COLUMN);
} catch (PDOException $exception) { if (count($results) === 0) {
$this->logger->error($exception); return false;
throw new EmptyResult($query, $exception); }
if (array_any($results, fn($secret) => $this->hmac->validate($timestamp, $signature, $eventId, $secret))) {
return true;
}
} catch (Throwable $throwable) {
$this->logger->error($throwable);
} }
return false;
} }
} }

View File

@ -29,15 +29,15 @@ class Customer extends AbstractEndPoint
$request_uri = "/customers/{$id}"; $request_uri = "/customers/{$id}";
return $this->sendGet($request_uri, [200], [404, 422]); return $this->sendGet($request_uri, [200], [404, 422]);
} }
public function add(array $data, ?string $accountKey = null): bool public function add(array $data): bool
{ {
$request_uri = "/customers"; $request_uri = "/customers";
return $this->sendAdd($request_uri, $data, [200, 201], [400, 422], $accountKey); return $this->sendAdd($request_uri, $data, [200, 201], [400, 422]);
} }
public function edit(string $id, array $data, ?string $accountKey = null): bool public function edit(string $id, array $data): bool
{ {
$request_uri = "customers/{$id}"; $request_uri = "customers/{$id}";
return $this->sendEdit($request_uri, $data, [200], [400, 404, 422], $accountKey); return $this->sendEdit($request_uri, $data, [200], [400, 404, 422]);
} }
public function delete(string $id): void public function delete(string $id): void
{ {

View File

@ -4,7 +4,6 @@ namespace Incoviba\Service\Venta\MediosPago\Toku;
use DateMalformedStringException; use DateMalformedStringException;
use DateTimeImmutable; use DateTimeImmutable;
use DateTimeZone; use DateTimeZone;
use PDO;
use PDOException; use PDOException;
use Psr\Http\Client\ClientInterface; use Psr\Http\Client\ClientInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -40,15 +39,15 @@ class Invoice extends AbstractEndPoint
$request_uri = "/invoices/{$id}"; $request_uri = "/invoices/{$id}";
return $this->sendGet($request_uri, [200], [404]); return $this->sendGet($request_uri, [200], [404]);
} }
public function add(array $data, ?string $accountKey = null): bool public function add(array $data): bool
{ {
$request_uri = "/invoices"; $request_uri = "/invoices";
return $this->sendAdd($request_uri, $data, [200, 201], [400, 409, 422], $accountKey); return $this->sendAdd($request_uri, $data, [200, 201], [400, 409, 422]);
} }
public function edit(string $id, array $data, ?string $accountKey = null): bool public function edit(string $id, array $data): bool
{ {
$request_uri = "/invoices/{$id}"; $request_uri = "/invoices/{$id}";
return $this->sendEdit($request_uri, $data, [200], [400, 404, 409, 422], $accountKey); return $this->sendEdit($request_uri, $data, [200], [400, 404, 409, 422]);
} }
public function delete(string $id): void public function delete(string $id): void
{ {
@ -200,41 +199,6 @@ class Invoice extends AbstractEndPoint
return $this->pagoService->depositar($invoice->cuota->pago, $date); return $this->pagoService->depositar($invoice->cuota->pago, $date);
} }
/**
* @param array $idsData
* @return array
* @throws EmptyResult
*/
public function updateAll(array $idsData): array
{
$tokuIds = array_column($idsData, 'toku_id');
$oldIds = array_column($idsData, 'product_id');
$placeholders = array_map(fn($id) => "id{$id}", array_keys($oldIds));
$placeholdersString = implode(', ', array_map(fn($id) => ":{$id}", $placeholders));
$query = $this->pagoService->getRepository()->getConnection()->getQueryBuilder()
->select('pago.id, CONCAT_WS("-", unidad.descripcion, CONCAT_WS("-", propietario.rut, propietario.dv)) AS old_pid')
->from('pago')
->joined('JOIN cuota ON cuota.pago = pago.id')
->joined('JOIN venta ON venta.pie = cuota.pie')
->joined('JOIN propietario ON propietario.rut = venta.propietario')
->joined('JOIN propiedad_unidad pu ON pu.propiedad = venta.propiedad')
->joined('JOIN unidad ON pu.unidad = unidad.id')
->having("old_pid IN ({$placeholdersString})");
$values = array_combine($placeholders, $oldIds);
try {
$statement = $this->pagoService->getRepository()->getConnection()->execute($query, $values);
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $exception) {
$this->logger->error($exception);
throw new EmptyResult($query, $exception);
}
$ids = array_column($results, 'pago.id');
$newIds = array_combine($ids, $tokuIds);
return array_map(fn($id) => ['product_id' => $id, 'toku_id' => $newIds[$id]], $ids);
}
public function save(array $data): bool public function save(array $data): bool
{ {
return $this->doSave($this->invoiceRepository, $data); return $this->doSave($this->invoiceRepository, $data);
@ -251,7 +215,7 @@ class Invoice extends AbstractEndPoint
{ {
$paramsMap = [ $paramsMap = [
'customer' => 'customer', 'customer' => 'customer',
'product_id' => 'cuota_id', 'product_id' => 'product_id',
'due_date' => 'fecha', 'due_date' => 'fecha',
'subscription' => 'subscription', 'subscription' => 'subscription',
'amount' => 'valor', 'amount' => 'valor',

View File

@ -1,7 +1,6 @@
<?php <?php
namespace Incoviba\Service\Venta\MediosPago\Toku; namespace Incoviba\Service\Venta\MediosPago\Toku;
use PDO;
use PDOException; use PDOException;
use Psr\Http\Client\ClientInterface; use Psr\Http\Client\ClientInterface;
use Incoviba\Common\Implement\Exception\EmptyResponse; use Incoviba\Common\Implement\Exception\EmptyResponse;
@ -35,15 +34,15 @@ class Subscription extends AbstractEndPoint
$request_uri = "/subscriptions/{$id}"; $request_uri = "/subscriptions/{$id}";
return $this->sendGet($request_uri, [200], [401, 404, 422]); return $this->sendGet($request_uri, [200], [401, 404, 422]);
} }
public function add(array $data, ?string $accountKey = null): bool public function add(array $data): bool
{ {
$request_uri = '/subscriptions'; $request_uri = '/subscriptions';
return $this->sendAdd($request_uri, $data, [200, 201], [401, 404, 409, 422], $accountKey); return $this->sendAdd($request_uri, $data, [200, 201], [401, 404, 409, 422]);
} }
public function edit(string $id, array $data, ?string $accountKey = null): bool public function edit(string $id, array $data): bool
{ {
$request_uri = "/subscriptions/{$id}"; $request_uri = "/subscriptions/{$id}";
return $this->sendEdit($request_uri, $data, [200], [401, 404, 409, 422], $accountKey); return $this->sendEdit($request_uri, $data, [200], [401, 404, 409, 422]);
} }
public function delete(string $id): void public function delete(string $id): void
{ {
@ -112,101 +111,6 @@ class Subscription extends AbstractEndPoint
} }
} }
/**
* @param array $idsData
* @return array
* @throws EmptyResult
* @throws EmptyResponse
*/
public function update(array $idsData): array
{
$tokuIds = array_column($idsData, 'toku_id');
$oldPids = array_column($idsData, 'product_id');
$placeholders = array_map(fn($id) => "id{$id}", array_keys($oldPids));
$placeholdersString = implode(', ', array_map(fn($id) => ":{$id}", $placeholders));
$query = $this->ventaService->getRepository()->getConnection()->getQueryBuilder()
->select('venta.id, CONCAT_WS("-", unidad.descripcion, CONCAT_WS("-", propietario.rut, propietario.dv)) AS old_pid')
->from('venta')
->joined('JOIN propietario ON propietario.rut = venta.propietario')
->joined('JOIN propiedad_unidad pu ON pu.propiedad = venta.propiedad')
->joined('JOIN unidad ON pu.unidad = unidad.id')
->having("old_pid IN ({$placeholdersString})");
$values = array_combine($placeholders, $oldPids);
try {
$statement = $this->ventaService->getRepository()->getConnection()->execute($query, $values);
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $exception) {
$this->logger->error($exception->getMessage(), [
'query' => $query,
'values' => $values,
'ids' => $idsData,
'exception' => $exception]);
throw new EmptyResult($query, $exception);
}
$accountKeys = $this->getAccountKey(array_column($results, 'id'));
$newPids = [];
$keys = [];
foreach ($results as $result) {
$idx = array_search($result['old_pid'], $oldPids);
$newPids[$idx] = $result['id'];
if (array_key_exists($result['id'], $accountKeys)) {
$keys[$idx] = $accountKeys[$result['id']];
}
}
$output = [];
foreach ($tokuIds as $idx => $tokuId) {
if (!isset($newPids[$idx])) {
continue;
}
$data = [
'product_id' => $newPids[$idx],
];
try {
if (!$this->edit($tokuId, $data, array_key_exists($idx, $keys) ? $keys[$idx] : null)) {
$this->logger->error('Error while updating Toku', [
'toku_id' => $tokuId,
'old_pid' => $oldPids[$idx],
'product_id' => $newPids[$idx],
'account_key' => array_key_exists($idx, $keys) ? $keys[$idx] : null]);
$output[] = [
'toku_id' => $tokuId,
'old_pid' => $oldPids[$idx],
'product_id' => $newPids[$idx],
'account_key' => array_key_exists($idx, $keys) ? $keys[$idx] : null,
'error' => 'Error while updating Toku'
];
continue;
}
} catch (EmptyResponse $exception) {
$this->logger->error($exception->getMessage(), [
'toku_id' => $tokuId,
'old_pid' => $oldPids[$idx],
'product_id' => $newPids[$idx],
'account_key' => array_key_exists($idx, $keys) ? $keys[$idx] : null,
'exception' => $exception]);
$output[] = [
'toku_id' => $tokuId,
'old_pid' => $oldPids[$idx],
'product_id' => $newPids[$idx],
'account_key' => array_key_exists($idx, $keys) ? $keys[$idx] : null,
'error' => $exception->getMessage()
];
continue;
}
$output[] = [
'toku_id' => $tokuId,
'old_pid' => $oldPids[$idx],
'product_id' => $newPids[$idx],
'account_key' => array_key_exists($idx, $keys) ? $keys[$idx] : null
];
}
return $output;
}
public function save(array $data): bool public function save(array $data): bool
{ {
return $this->doSave($this->subscriptionRepsitory, $data); return $this->doSave($this->subscriptionRepsitory, $data);
@ -229,11 +133,11 @@ class Subscription extends AbstractEndPoint
if ($ref === null) { if ($ref === null) {
continue; continue;
} }
if ($ref === 'pieValor' and array_key_exists('venta', $data)) { if ($ref === 'pieValor') {
$params[$key] = $data['venta']?->formaPago()?->pie?->valor ?? 0; $params[$key] = $data['venta']->formaPago()?->pie?->valor ?? 0;
continue; continue;
} }
if ($ref === 'datosVenta' and array_key_exists('venta', $data)) { if ($ref === 'datosVenta') {
$params[$key] = $this->datosVenta($data['venta']); $params[$key] = $this->datosVenta($data['venta']);
continue; continue;
} }
@ -265,38 +169,4 @@ class Subscription extends AbstractEndPoint
'Unidades' => $venta->propiedad()->summary() 'Unidades' => $venta->propiedad()->summary()
]; ];
} }
/**
* @param array $ventaIds
* @return array
* @throws EmptyResult
*/
protected function getAccountKey(array $ventaIds): array
{
$placeholders = array_map(fn($id) => "id{$id}", array_keys($ventaIds));
$placeholdersString = implode(', ', array_map(fn($id) => ":{$id}", $placeholders));
$query = $this->ventaService->getRepository()->getConnection()->getQueryBuilder()
->select('account_key, venta.id AS venta_id')
->from('toku_accounts')
->joined('JOIN proyecto ON proyecto.inmobiliaria = toku_accounts.sociedad_rut')
->joined('JOIN proyecto_tipo_unidad ptu ON ptu.proyecto = proyecto.id')
->joined('JOIN unidad ON unidad.pt = ptu.id')
->joined('JOIN propiedad_unidad pu ON pu.unidad = unidad.id')
->joined('JOIN venta ON venta.propiedad = pu.propiedad')
->where("venta.id IN ({$placeholdersString}) AND toku_accounts.enabled = 1");
$values = array_combine($placeholders, $ventaIds);
try {
$statement = $this->ventaService->getRepository()->getConnection()->execute($query, $values);
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $exception) {
$this->logger->error($exception->getMessage(), [
'query' => $query,
'values' => $values,
'exception' => $exception]);
throw new EmptyResult($query, $exception);
}
$keys = array_column($results, 'account_key');
$ids = array_column($results, 'venta_id');
return array_combine($ids, $keys);
}
} }

View File

@ -4,37 +4,25 @@ namespace Incoviba\Service\Venta;
use DateTimeInterface; use DateTimeInterface;
use DateTimeImmutable; use DateTimeImmutable;
use DateMalformedStringException; use DateMalformedStringException;
use Incoviba\Common\Define;
use Incoviba\Exception\ServiceAction\Create; use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Exception\ServiceAction\Read; use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Exception\ServiceAction\Update; use Incoviba\Exception\ServiceAction\Update;
use PDOException; use PDOException;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Model; use Incoviba\Model;
use Incoviba\Service; use Incoviba\Service;
use Psr\Log\LoggerInterface;
class Pago extends Ideal\Service\Repository class Pago
{ {
public function __construct( public function __construct(
LoggerInterface $logger,
protected Repository\Venta\Pago $pagoRepository, protected Repository\Venta\Pago $pagoRepository,
protected Repository\Venta\EstadoPago $estadoPagoRepository, protected Repository\Venta\EstadoPago $estadoPagoRepository,
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository, protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
protected Service\UF $ufService, protected Service\UF $ufService,
protected Service\Valor $valorService, protected Service\Valor $valorService,
protected Service\Queue $queueService protected Service\Queue $queueService
) ) {}
{
parent::__construct($logger);
}
public function getRepository(): Define\Repository
{
return $this->pagoRepository;
}
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
{ {

View File

@ -1,31 +1,19 @@
<?php <?php
namespace Incoviba\Service\Venta; namespace Incoviba\Service\Venta;
use DateTimeInterface;
use PDOException;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction; use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Model;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Model;
class Precio extends Ideal\Service class Precio
{ {
public function __construct(LoggerInterface $logger, public function __construct(protected Repository\Venta\Precio $precioRepository, protected Repository\Venta\EstadoPrecio $estadoPrecioRepository) {}
protected Repository\Venta\Precio $precioRepository,
protected Repository\Venta\EstadoPrecio $estadoPrecioRepository,
protected Precio\Estado $estadoPrecioService,
protected Precio\Import $importService)
{
parent::__construct($logger);
}
/** /**
* @param int $proyecto_id * @param int $proyecto_id
* @return array * @return array
* @throws ServiceAction\Read * @throws Read
*/ */
public function getByProyecto(int $proyecto_id): array public function getByProyecto(int $proyecto_id): array
{ {
@ -37,14 +25,14 @@ class Precio extends Ideal\Service
} }
return $precios; return $precios;
} catch (EmptyResult $exception) { } catch (EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception); throw new Read(__CLASS__, $exception);
} }
} }
/** /**
* @param int $unidad_id * @param int $unidad_id
* @return Model\Venta\Precio * @return Model\Venta\Precio
* @throws ServiceAction\Read * @throws Read
*/ */
public function getVigenteByUnidad(int $unidad_id): Model\Venta\Precio public function getVigenteByUnidad(int $unidad_id): Model\Venta\Precio
{ {
@ -54,14 +42,14 @@ class Precio extends Ideal\Service
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id); $precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
return $precio; return $precio;
} catch (EmptyResult $exception) { } catch (EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception); throw new Read(__CLASS__, $exception);
} }
} }
/** /**
* @param int $unidad_id * @param int $unidad_id
* @return array * @return array
* @throws ServiceAction\Read * @throws Read
*/ */
public function getByUnidad(int $unidad_id): array public function getByUnidad(int $unidad_id): array
{ {
@ -73,51 +61,7 @@ class Precio extends Ideal\Service
} }
return $precios; return $precios;
} catch (EmptyResult $exception) { } catch (EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception); throw new Read(__CLASS__, $exception);
} }
} }
/**
* @param int $projectId
* @param DateTimeInterface $date
* @param UploadedFileInterface $uploadedFile
* @return array
* @throws ServiceAction\Create
*/
public function import(int $projectId, DateTimeInterface $date, UploadedFileInterface $uploadedFile): array
{
$pricesData = $this->importService->importData($projectId, $date, $uploadedFile);
$prices = [];
foreach ($pricesData as $data) {
try {
$price = $this->precioRepository->create($data);
$price = $this->precioRepository->save($price);
$prices[] = $price;
} catch (EmptyResult | PDOException $exception) {
$this->logger->error('Problemas para agregar precio', ['data' => $data, 'exception' => $exception]);
}
}
foreach ($prices as $price) {
$idx = array_search($price->unidad->id, array_column($pricesData, 'unidad'));
$row = $pricesData[$idx];
try {
$this->estadoPrecioService->replacePrices($price->unidad, $date, $price);
} catch (ServiceAction\Update $exception) {
$this->logger->error('Problemas para reemplazar precios', [
'data' => $row,
'exception' => $exception
]);
}
try {
$this->estadoPrecioService->updatePrice($price, $row['fecha']);
} catch (ServiceAction\Update $exception) {
$this->logger->error('Problemas para actualizar estado de precio', [
'data' => $row,
'exception' => $exception
]);
}
}
return $prices;
}
} }

View File

@ -1,89 +0,0 @@
<?php
namespace Incoviba\Service\Venta\Precio;
use DateTimeInterface;
use Incoviba\Model\Venta\Precio;
use Incoviba\Model\Venta\Unidad;
use PDOException;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Exception\ServiceAction;
use Incoviba\Model;
use Incoviba\Repository;
class Estado extends Ideal\Service
{
public function __construct(LoggerInterface $logger,
protected Repository\Venta\Precio $precioRepository,
protected Repository\Venta\EstadoPrecio $estadoPrecioRepository,
protected Repository\Venta\TipoEstadoPrecio $tipoEstadoPrecioRepository)
{
parent::__construct($logger);
}
/**
* @param Model\Venta\Precio $price
* @param DateTimeInterface $date
* @return void
* @throws ServiceAction\Update
*/
public function updatePrice(Model\Venta\Precio $price, DateTimeInterface $date): void
{
try {
$tipoEstado = $this->tipoEstadoPrecioRepository->fetchByDescripcion('vigente');
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
$data = [
'precio' => $price->id,
'fecha' => $date->format('Y-m-d'),
'estado' => $tipoEstado->id
];
try {
$estado = $this->estadoPrecioRepository->create($data);
$this->estadoPrecioRepository->save($estado);
} catch (Implement\Exception\EmptyResult | PDOException $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
}
/**
* @param Unidad $unidad
* @param DateTimeInterface $date
* @param Precio $price
* @return void
* @throws ServiceAction\Update
*/
public function replacePrices(Model\Venta\Unidad $unidad, DateTimeInterface $date, Model\Venta\Precio $price): void
{
try {
$tipoEstado = $this->tipoEstadoPrecioRepository->fetchByDescripcion('reemplazado');
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
try {
$precios = $this->precioRepository->fetchByUnidad($unidad->id);
foreach ($precios as $p) {
if ($p->id === $price->id) {
continue;
}
try {
$estado = $this->estadoPrecioRepository->fetchCurrentByPrecio($p->id);
if ($estado->tipoEstadoPrecio->id === $tipoEstado->id) {
continue;
}
$data = [
'precio' => $p->id,
'estado' => $tipoEstado->id,
'fecha' => $date->format('Y-m-d')
];
$estado = $this->estadoPrecioRepository->create($data);
$this->estadoPrecioRepository->save($estado);
} catch (Implement\Exception\EmptyResult) {}
}
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
}
}

View File

@ -1,243 +0,0 @@
<?php
namespace Incoviba\Service\Venta\Precio;
use DateTime;
use DateTimeInterface;
use PDOException;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction;
use Incoviba\Model;
use Incoviba\Service;
use Incoviba\Repository;
class Import extends Ideal\Service
{
public function __construct(LoggerInterface $logger,
protected Repository\Venta\Precio $precioRepository,
protected Repository\Inmobiliaria $inmobiliariaRepository,
protected Repository\Proyecto $proyectoRepository,
protected Repository\Venta\Unidad $unidadRepository,
protected Service\FileUpload $fileUploadService)
{
parent::__construct($logger);
}
/**
* @param int $projectId
* @param DateTimeInterface $date
* @param UploadedFileInterface $uploadedFile
* @return array
* @throws ServiceAction\Create
*/
public function importData(int $projectId, DateTimeInterface $date, UploadedFileInterface $uploadedFile): array
{
try {
$data = $this->fileUploadService->getData($uploadedFile);
} catch (ServiceAction\Read $exception) {
throw new ServiceAction\Create(__CLASS__, $exception);
}
$mappedData = $this->mapData($data, $projectId, $date);
$pricesData = [];
foreach ($mappedData as $row) {
$pricesData[] = [
'unidad' => $row['unidad'],
'valor' => $row['precio'],
'fecha' => $row['fecha']
];
}
try {
$priceUnitIds = array_map(fn($price) => $price['unidad'], $pricesData);
$prices = $this->precioRepository->fetchVigentesByUnidades($priceUnitIds);
$priceUnitIds = array_map(fn(array $p) => $p['id'], $prices);
$pricePrices = array_map(fn(array $p) => $p['precio']->valor, $prices);
return array_filter($pricesData, function($price) use ($priceUnitIds, $pricePrices) {
$idx = array_search($price['unidad'], $priceUnitIds);
if ($idx === false) {
return true;
}
return $pricePrices[$idx] !== $price['valor'];
});
} catch (EmptyResult $exception) {
throw new ServiceAction\Create(__CLASS__, $exception);
}
}
protected array $realTitlesMap;
protected function extractTitlesFromData(array $data): array
{
if (isset($this->realTitlesMap)) {
return $this->realTitlesMap;
}
$baseTitlesMap = [
'proyecto' => [],
'precio' => [],
'unidad' => ['departamento'],
'tipo' => ['tipo unidad'],
'fecha' => []
];
$realTitlesMap = [];
$titles = array_keys($data[0]);
foreach ($baseTitlesMap as $base => $optionals) {
foreach ($titles as $title) {
if (str_contains($title, $base)) {
$realTitlesMap[$title] = $base;
break;
}
foreach ($optionals as $optional) {
if (str_contains($title, $optional)) {
$realTitlesMap[$title] = $base;
break;
}
}
}
}
return $this->realTitlesMap = $realTitlesMap;
}
protected function mapData(array $data, int $projectId, DateTimeInterface $date): array
{
$mappedData = $this->mapTitles($data);
$mappedData = $this->mapProjects($mappedData, $projectId);
$mappedData = $this->mapUnits($mappedData);
return $this->mapDates($mappedData, $date);
}
protected function mapTitles(array $data): array
{
$titlesMap = $this->extractTitlesFromData($data);
$mappedData = [];
foreach ($data as $row) {
$mappedData []= $this->mapRow($row, $titlesMap);
}
return $mappedData;
}
protected function mapProjects(array $data, int $projectId): array
{
if (!array_key_exists('proyecto', $data[0])) {
return array_map(function($row) use ($projectId) {
$row['proyecto'] = $projectId;
return $row;
},$data);
}
$projects = $this->extractProjectsFromData($data);
$mappedData = [];
foreach ($data as $row) {
$mappedRow = $row;
$mappedRow['proyecto'] = $projects[$row['proyecto']]?->id ?? $projectId;
$mappedData []= $mappedRow;
}
return $mappedData;
}
protected function mapUnits(array $data): array
{
if (!array_key_exists('unidad', $data[0]) or !array_key_exists('tipo', $data[0])) {
return $data;
}
$unidades = [];
$mappedData = [];
foreach ($data as $row) {
if (!isset($unidades[$row['proyecto']])) {
$unidades[$row['proyecto']] = $this->unidadRepository->fetchByProyecto($row['proyecto']);
}
$tipo = $this->mapTipoUnidad($row['tipo']);
$unidad = array_filter($unidades[$row['proyecto']], function(Model\Venta\Unidad $unidad) use ($row, $tipo) {
return $unidad->descripcion == $row['unidad']
and $unidad->proyectoTipoUnidad->tipoUnidad->descripcion == $tipo;
});
if (count($unidad) === 0) {
$this->logger->warning('Unidad no encontrada', ['row' => $row]);
continue;
}
$mappedRow = $row;
$mappedRow['unidad'] = array_shift($unidad)->id;
unset($mappedRow['tipo']);
$mappedData []= $mappedRow;
}
return $mappedData;
}
protected function mapDates(array $data, DateTimeInterface $date): array
{
if (!array_key_exists('fecha', $data[0])) {
return array_map(function($row) use ($date) {
$row['fecha'] = $date;
return $row;
}, $data);
}
$mappedData = [];
foreach ($data as $row) {
$mappedRow = $row;
$newDate = DateTime::createFromFormat('d/m/Y', $row['fecha']);
$mappedRow['fecha'] = $newDate;
if ($newDate === false) {
$mappedRow['fecha'] = $date;
}
$mappedData []= $mappedRow;
}
return $mappedData;
}
protected function mapRow(array $row, array $titlesMap): array
{
$mappedRow = [];
foreach ($row as $key => $value) {
$mappedRow[$titlesMap[$key]] = $value;
}
return $mappedRow;
}
protected function mapTipoUnidad(string $tipo): string
{
if (str_contains(mb_strtolower($tipo), 'bod')) {
return 'bodega';
}
if (str_contains(mb_strtolower($tipo), 'est')) {
return 'estacionamiento';
}
if (str_contains(mb_strtolower($tipo), 'terr')) {
return 'terraza';
}
return 'departamento';
}
protected array $projectsMap;
protected function extractProjectsFromData(array $data): array
{
if (isset($this->projectsMap)) {
return $this->projectsMap;
}
$projectNames = array_unique(array_map(fn($row) => $row['proyecto'], $data));
$projects = [];
foreach ($projectNames as $projectName) {
try {
$projects[$projectName] = $this->proyectoRepository->fetchByName($projectName);
} catch (EmptyResult $exception) {
try {
$inm = $this->inmobiliariaRepository->fetchByName($projectName);
$inmProjects = $this->proyectoRepository->fetchByInmobiliaria($inm->rut);
$projects[$projectName] = $inmProjects[0];
} catch (EmptyResult $exception2) {
$this->logger->warning('Neither Project nor Society found', [
'projectName' => $projectName,
'exceptions' => [
[
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'data' => $exception->getData(),
'trace' => $exception->getTraceAsString()
],
[
'code' => $exception2->getCode(),
'message' => $exception2->getMessage(),
'file' => $exception2->getFile(),
'line' => $exception2->getLine(),
'data' => $exception2->getData(),
'trace' => $exception2->getTraceAsString()
]
],
]);
}
}
}
return $this->projectsMap = $projects;
}
}

View File

@ -48,20 +48,6 @@ class Promotion extends Ideal\Service
} }
} }
/**
* @param int $project_id
* @return array
* @throws Exception\ServiceAction\Read
*/
public function getByProject(int $project_id): array
{
try {
return array_map([$this, 'process'], $this->promotionRepository->fetchByProject($project_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Read(__CLASS__, $exception);
}
}
/** /**
* @param int $contract_id * @param int $contract_id
* @return array * @return array

View File

@ -1,24 +1,22 @@
<?php <?php
namespace Incoviba\Service\Venta; namespace Incoviba\Service\Venta;
use PDOException;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal\Service; use Incoviba\Common\Ideal\Service;
use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Create; use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Exception\ServiceAction\Read; use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Exception\ServiceAction\Update; use Incoviba\Exception\ServiceAction\Update;
use Incoviba\Model;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Service\Valor; use Incoviba\Model;
use PDOException;
use Psr\Log\LoggerInterface;
class Propietario extends Service class Propietario extends Service
{ {
public function __construct( public function __construct(
LoggerInterface $logger, LoggerInterface $logger,
protected Repository\Venta\Propietario $propietarioRepository, protected Repository\Venta\Propietario $propietarioRepository,
protected Repository\Direccion $direccionRepository, protected Repository\Direccion $direccionRepository
protected Valor $valorService
) { ) {
parent::__construct($logger); parent::__construct($logger);
} }
@ -51,9 +49,6 @@ class Propietario extends Service
$data['direccion'] = $direccion->id; $data['direccion'] = $direccion->id;
} }
$filteredData = $this->propietarioRepository->filterData($data); $filteredData = $this->propietarioRepository->filterData($data);
if (array_key_exists('telefono', $filteredData)) {
$filteredData['telefono'] = $this->valorService->telefono()->toDatabase($filteredData['telefono']);
}
try { try {
return $this->propietarioRepository->edit($propietario, $filteredData); return $this->propietarioRepository->edit($propietario, $filteredData);
} catch (PDOException | EmptyResult $exception) { } catch (PDOException | EmptyResult $exception) {
@ -90,10 +85,6 @@ class Propietario extends Service
]); ]);
$filtered_data = array_intersect_key($data, $fields); $filtered_data = array_intersect_key($data, $fields);
if (array_key_exists('telefono', $filtered_data)) {
$filtered_data['telefono'] = $this->valorService->telefono()->toDatabase($filtered_data['telefono']);
}
try { try {
$propietario = $this->propietarioRepository->fetchById($data['rut']); $propietario = $this->propietarioRepository->fetchById($data['rut']);
$edits = []; $edits = [];
@ -104,7 +95,6 @@ class Propietario extends Service
} catch (EmptyResult) { } catch (EmptyResult) {
try { try {
$propietario = $this->propietarioRepository->create($filtered_data); $propietario = $this->propietarioRepository->create($filtered_data);
$this->logger->info('Propietario', ['propietario' => $propietario]);
$propietario = $this->propietarioRepository->save($propietario); $propietario = $this->propietarioRepository->save($propietario);
} catch (PDOException $exception) { } catch (PDOException $exception) {
throw new Create(__CLASS__, $exception); throw new Create(__CLASS__, $exception);

View File

@ -1,10 +1,8 @@
<?php <?php
namespace Incoviba\Service\Venta; namespace Incoviba\Service\Venta;
use DateMalformedStringException;
use DateTimeImmutable; use DateTimeImmutable;
use DateTimeInterface; use DateMalformedStringException;
use Incoviba\Exception\ServiceAction\Read;
use PDOException; use PDOException;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Incoviba\Common\Define; use Incoviba\Common\Define;
@ -13,16 +11,10 @@ use Incoviba\Common\Implement;
use Incoviba\Exception\ServiceAction; use Incoviba\Exception\ServiceAction;
use Incoviba\Model; use Incoviba\Model;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Service;
class Reservation extends Ideal\Service\API class Reservation extends Ideal\Service\API
{ {
public function __construct(LoggerInterface $logger, public function __construct(LoggerInterface $logger, protected Repository\Venta\Reservation $reservationRepository)
protected Repository\Venta\Reservation $reservationRepository,
protected Repository\Venta\Reservation\State $stateRepository,
protected Service\Persona $personaService,
protected Service\Proyecto\Broker $brokerService,
protected Promotion $promotionService, protected Unidad $unitService)
{ {
parent::__construct($logger); parent::__construct($logger);
} }
@ -30,26 +22,12 @@ class Reservation extends Ideal\Service\API
public function getAll(null|string|array $order = null): array public function getAll(null|string|array $order = null): array
{ {
try { try {
return array_map([$this, 'process'], $this->reservationRepository->fetchAll($order)); return $this->reservationRepository->fetchAll($order);
} catch (Implement\Exception\EmptyResult) { } catch (Implement\Exception\EmptyResult) {
return []; return [];
} }
} }
/**
* @param int $project_id
* @return array
* @throws ServiceAction\Read
*/
public function getByProject(int $project_id): array
{
try {
return array_map([$this, 'process'], $this->reservationRepository->fetchByProject($project_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
public function get(int $id): Model\Venta\Reservation public function get(int $id): Model\Venta\Reservation
{ {
try { try {
@ -59,130 +37,24 @@ class Reservation extends Ideal\Service\API
} }
} }
/**
* @param int $buyer_rut
* @param DateTimeInterface $date
* @return Model\Venta\Reservation
* @throws Read
*/
public function getByBuyerAndDate(int $buyer_rut, DateTimeInterface $date): Model\Venta\Reservation
{
try {
return $this->process($this->reservationRepository->fetchByBuyerAndDate($buyer_rut, $date));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
/**
* @param int $project_id
* @return array
* @throws ServiceAction\Read
*/
public function getActive(int $project_id): array
{
try {
return array_map([$this, 'process'], $this->reservationRepository->fetchActive($project_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
/**
* @param int $project_id
* @return array
* @throws ServiceAction\Read
*/
public function getPending(int $project_id): array
{
try {
return array_map([$this, 'process'], $this->reservationRepository->fetchPending($project_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
/**
* @param int $project_id
* @return array
* @throws ServiceAction\Read
*/
public function getRejected(int $project_id): array
{
try {
return array_map([$this, 'process'], $this->reservationRepository->fetchRejected($project_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
public function add(array $data): Model\Venta\Reservation public function add(array $data): Model\Venta\Reservation
{ {
$date = new DateTimeImmutable();
try { try {
$date = new DateTimeImmutable($data['date']); $date = new DateTimeImmutable();
} catch (DateMalformedStringException) {}
try {
$reservation = $this->reservationRepository->fetchByBuyerAndDate($data['buyer_rut'], $date);
if (array_key_exists('broker_rut', $data) and $data['broker_rut'] !== '') {
try {
$broker = $this->brokerService->get($data['broker_rut']);
$reservation = $this->reservationRepository->edit($reservation, ['broker_rut' => $broker->rut]);
} catch (ServiceAction\Read) {}
}
} catch (Implement\Exception\EmptyResult) {
if (!$this->reservationRepository->getConnection()->getPDO()->inTransaction()) {
$this->reservationRepository->getConnection()->getPDO()->beginTransaction();
}
$buyerData = [];
foreach ($data as $key => $value) {
if (!str_starts_with($key, 'buyer_')) {
continue;
}
$buyerData[substr($key, strlen('buyer_'))] = $value;
}
$this->personaService->add($buyerData);
$data['date'] = $date->format('Y-m-d');
try { try {
$reservationData = $this->reservationRepository->filterData($data); $date = new DateTimeImmutable($data['date']);
$reservation = $this->reservationRepository->create($reservationData); } catch (DateMalformedStringException) {}
$reservation = $this->reservationRepository->save($reservation); return $this->process($this->reservationRepository->fetchByBuyerAndDate($data['buyer_rut'], $date));
} catch (Implement\Exception\EmptyResult) {}
$stateType = Model\Venta\Reservation\State\Type::INACTIVE; try {
$stateData = [ $reservationData = $this->reservationRepository->filterData($data);
'reservation_id' => $reservation->id, $reservation = $this->reservationRepository->create($reservationData);
'date' => $data['date'], $this->reservationRepository->save($reservation);
'type' => $stateType->value, return $this->process($reservation);
]; } catch (PDOException $exception) {
$state = $this->stateRepository->create($stateData); throw new ServiceAction\Create(__CLASS__, $exception);
$this->stateRepository->save($state);
$units = array_combine($data['units'], $data['units_value']);
$this->addUnits($reservation, $units);
if (array_key_exists('broker_rut', $data) and !empty($data['broker_rut'])) {
$this->addBroker($reservation, $data['broker_rut']);
}
if (array_key_exists('promotions', $data)) {
$this->addPromotions($reservation, $data['promotions']);
}
if ($this->reservationRepository->getConnection()->getPDO()->inTransaction()) {
$this->reservationRepository->getConnection()->getPDO()->commit();
}
} catch (PDOException $exception) {
$this->logger->warning($exception->getMessage(), ['exception' => $exception->getTraceAsString()]);
if ($this->reservationRepository->getConnection()->getPDO()->inTransaction()) {
$this->reservationRepository->getConnection()->getPDO()->rollBack();
}
throw new ServiceAction\Create(__CLASS__, $exception);
}
} }
return $this->process($reservation);
} }
public function edit(Define\Model $model, array $new_data): Model\Venta\Reservation public function edit(Define\Model $model, array $new_data): Model\Venta\Reservation
{ {
@ -202,82 +74,8 @@ class Reservation extends Ideal\Service\API
throw new ServiceAction\Delete(__CLASS__, $exception); throw new ServiceAction\Delete(__CLASS__, $exception);
} }
} }
/**
* @param Model\Venta\Reservation $reservation
* @return void
* @throws ServiceAction\Update
*/
public function approve(Model\Venta\Reservation $reservation): void
{
try {
$stateData = [
'reservation_id' => $reservation->id,
'date' => new DateTimeImmutable(),
'type' => Model\Venta\Reservation\State\Type::ACTIVE->value,
];
$state = $this->stateRepository->create($stateData);
$this->stateRepository->save($state);
} catch (PDOException $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
}
public function reject(Model\Venta\Reservation $reservation): void
{
try {
$stateData = [
'reservation_id' => $reservation->id,
'date' => new DateTimeImmutable(),
'type' => Model\Venta\Reservation\State\Type::REJECTED->value,
];
$state = $this->stateRepository->create($stateData);
$this->stateRepository->save($state);
} catch (PDOException $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
}
protected function process(Define\Model $model): Model\Venta\Reservation protected function process(Define\Model $model): Model\Venta\Reservation
{ {
$model->addFactory('states', new Implement\Repository\Factory()
->setArgs(['reservation_id' => $model->id])
->setCallable(function(int $reservation_id) {
return $this->stateRepository->fetchByReservation($reservation_id);
})
);
$model->buyer = $this->personaService->getById($model->buyer->rut);
return $model; return $model;
} }
protected function addUnits(Model\Venta\Reservation $reservation, array $units): void
{
foreach ($units as $unit_id => $value) {
try {
$unit = $this->unitService->getById($unit_id);
} catch (ServiceAction\Read) {
continue;
}
$reservation->addUnit($unit, $value);
}
$this->reservationRepository->save($reservation);
}
protected function addBroker(Model\Venta\Reservation $reservation, int $broker_rut): void
{
try {
$broker = $this->brokerService->get($broker_rut);
$reservation->broker = $broker;
$this->reservationRepository->save($reservation);
} catch (ServiceAction\Read) {}
}
protected function addPromotions(Model\Venta\Reservation $reservation, array $promotions): void
{
foreach ($promotions as $promotion_id) {
try {
$promotion = $this->promotionService->getById($promotion_id);
} catch (ServiceAction\Read) {
continue;
}
$reservation->promotions []= $promotion;
}
$this->reservationRepository->save($reservation);
}
} }

Some files were not shown because too many files have changed in this diff Show More