diff --git a/helpers/ajustesHelper/ajustes.acta.helper.go b/helpers/ajustesHelper/ajustes.acta.helper.go index d5fca93c..637ee5ec 100644 --- a/helpers/ajustesHelper/ajustes.acta.helper.go +++ b/helpers/ajustesHelper/ajustes.acta.helper.go @@ -128,12 +128,24 @@ func fillElementos(elsOrg []*models.DetalleElemento_) (completos []*models.Detal } -func generarNuevosActa(nuevos []*models.DetalleElemento_) (actualizados []*models.Elemento, outputError map[string]interface{}) { +func generarNuevosActa(nuevos []*models.DetalleElemento_, originales []*models.Elemento) (actualizados []*models.Elemento, outputError map[string]interface{}) { funcion := "generarNuevosActa" defer errorCtrl.ErrorControlFunction(funcion+" - Unhandled Error!", "500") - outputError = utilsHelper.FillStruct(nuevos, &actualizados) + if outputError = utilsHelper.FillStruct(nuevos, &actualizados); outputError != nil { + return + } + + // El PUT a acta_recibido_crud reemplaza la fila completa; se preservan las + // fechas del elemento original para no violar el not-null de fecha_creacion. + for _, el := range actualizados { + if idx := findElementoInArrayE(originales, el.Id); idx > -1 { + el.FechaCreacion = originales[idx].FechaCreacion + el.FechaModificacion = originales[idx].FechaModificacion + } + } + return } diff --git a/helpers/ajustesHelper/ajustes.auto.helper.go b/helpers/ajustesHelper/ajustes.auto.helper.go index 6fe45842..2722fb96 100644 --- a/helpers/ajustesHelper/ajustes.auto.helper.go +++ b/helpers/ajustesHelper/ajustes.auto.helper.go @@ -159,7 +159,7 @@ func GenerarAjusteAutomatico(elementos []*models.DetalleElemento_) (resultado *m } if len(updateSg)+len(updateVls)+len(updateMsc) > 0 { - if nuevos, err := generarNuevosActa(append(updateSg, (append(updateVls, updateMsc...))...)); err != nil { + if nuevos, err := generarNuevosActa(append(updateSg, (append(updateVls, updateMsc...))...), orgiginalesActa); err != nil { return nil, err } else { nuevosActa = nuevos diff --git a/helpers/ajustesHelper/ajustes.movimientos.helper.go b/helpers/ajustesHelper/ajustes.movimientos.helper.go index 637729c7..802dbaa2 100644 --- a/helpers/ajustesHelper/ajustes.movimientos.helper.go +++ b/helpers/ajustesHelper/ajustes.movimientos.helper.go @@ -266,7 +266,7 @@ func generarMovimientoAjuste(sg, vls, msc, mp []*models.DetalleElemento_, movCon movimiento.FormatoTipoMovimientoId = fm[0] } - if sm, err := movimientosArka.GetAllEstadoMovimiento(url.QueryEscape("Ajuste Aprobado")); err != nil { + if sm, err := movimientosArka.GetAllEstadoMovimiento("query=Nombre:" + url.QueryEscape("Ajuste Aprobado")); err != nil { return nil, nil, err } else { movimiento.EstadoMovimientoId = sm[0] diff --git a/helpers/crud/consecutivos/Post.go b/helpers/crud/consecutivos/Post.go index fbefff30..dfa60225 100644 --- a/helpers/crud/consecutivos/Post.go +++ b/helpers/crud/consecutivos/Post.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" - "github.com/beego/beego/v2/core/logs" beego "github.com/beego/beego/v2/server/web" "github.com/udistrital/arka_mid/models" "github.com/udistrital/arka_mid/utils_oas/errorCtrl" @@ -23,14 +22,12 @@ func Post(consecutivo interface{}) (outputError map[string]interface{}) { response := new(models.RespuestaAPI1Interface) if err := request.SendJson(urlcrud, "POST", response, consecutivo); err != nil { - logs.Error(urlcrud + ", " + err.Error()) eval := ` - request.SendJson(urlcrud, "POST", response, consecutivo)` return errorCtrl.Error(funcion+eval, err, "502") } if !response.Success { err := fmt.Errorf("%v", response.Message) - logs.Error(err) eval := ` - request.SendJson(urlcrud, "POST", response, consecutivo)` return errorCtrl.Error(funcion+eval, err, "502") } @@ -56,28 +53,6 @@ func Post(consecutivo interface{}) (outputError map[string]interface{}) { err := fmt.Errorf("response.Data llegó como arreglo vacío") return errorCtrl.Error(funcion+" - response.Data vacío", err, "502") } - - // intentar encontrar el consecutivo correcto si el payload es *models.Consecutivo - if cons, ok := consecutivo.(*models.Consecutivo); ok { - for _, item := range data { - tmp := models.Consecutivo{} - raw, err := json.Marshal(item) - if err != nil { - continue - } - if err := json.Unmarshal(raw, &tmp); err != nil { - continue - } - - if tmp.ContextoId == cons.ContextoId && - tmp.Year == cons.Year && - tmp.Descripcion == cons.Descripcion { - return fill(item, consecutivo) - } - } - } - - // fallback: usar el último elemento return fill(data[len(data)-1], consecutivo) default: diff --git a/swagger/swagger.json b/swagger/swagger.json index 333dffb3..907e6ed2 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -1211,44 +1211,6 @@ } } }, - "/salida/{id}/anular": { - "put": { - "tags": [ - "salida" - ], - "description": "Anula una salida aprobada, registra un movimiento de reversión contable y restablece la entrada padre cuando corresponda.", - "operationId": "SalidaController.PutAnular", - "parameters": [ - { - "in": "path", - "name": "id", - "description": "Id de la salida a anular", - "required": true, - "type": "integer", - "format": "int64" - }, - { - "in": "body", - "name": "body", - "description": "Observación de la anulación", - "schema": { - "$ref": "#/definitions/models.AnulacionSalidaRequest" - } - } - ], - "responses": { - "200": { - "description": "", - "schema": { - "$ref": "#/definitions/models.ResultadoAnulacionSalida" - } - }, - "400": { - "description": "the request contains incorrect syntax" - } - } - } - }, "/inmuebles/": { "get": { "tags": [ @@ -1792,6 +1754,44 @@ } } }, + "/salida/{id}/anular": { + "put": { + "tags": [ + "salida" + ], + "description": "Anula una salida aprobada, registra un movimiento de reversión contable y restablece la entrada padre cuando corresponda.", + "operationId": "SalidaController.PutAnular", + "parameters": [ + { + "in": "path", + "name": "id", + "description": "Id de la salida a anular", + "required": true, + "type": "integer", + "format": "int64" + }, + { + "in": "body", + "name": "body", + "description": "Observación de la anulación", + "schema": { + "$ref": "#/definitions/models.AnulacionSalidaRequest" + } + } + ], + "responses": { + "200": { + "description": "", + "schema": { + "$ref": "#/definitions/models.ResultadoAnulacionSalida" + } + }, + "400": { + "description": "the request contains incorrect syntax" + } + } + } + }, "/terceros/{id}": { "get": { "tags": [ @@ -4796,4 +4796,4 @@ "description": "ReportesController operations for reportes\n" } ] -} +} \ No newline at end of file diff --git a/utils_oas/errorCtrl/errorCtrl.go b/utils_oas/errorCtrl/errorCtrl.go index 325b19e9..2758dba9 100644 --- a/utils_oas/errorCtrl/errorCtrl.go +++ b/utils_oas/errorCtrl/errorCtrl.go @@ -12,7 +12,11 @@ import ( func ErrorControlController(c web.Controller, controller string) { if err := recover(); err != nil { logs.Error(err) - localError := err.(map[string]interface{}) + localError, ok := err.(map[string]interface{}) + if !ok { + c.Abort(strconv.Itoa(http.StatusInternalServerError)) + return + } appName, _ := web.AppConfig.String("appname") c.Data["mesaage"] = (appName + "/" + controller + "/" + (localError["funcion"]).(string)) c.Data["data"] = normalizeErrorValue(localError["err"])