1.8.0 • Published 5 years ago
calculo-cuotas-frances-co v1.8.0
calculo-cuotas-frances
Librería para el cálculo/generación de cuotas dado un valor inicial o pie. Opcionalmente, se puede pasar por parámetro un objeto de configuración, el cual alterará los cálculos según los valores dados en dicha configuración.
Install
npm install -S calculo-cuotas-francesUsage
import getSimulation from 'calculo-cuotas-frances'// Se necesita pasar un objeto con 2 propiedades obligatorias: creditValue y carValue.
const opts = {
creditValue,
carValue
}
const installments = getSimulation(opts)
// =>
Simulation {
creditValue: 5600000,
carValue: 9000000,
installments: [
Installment { plan: 18, amount: 429678 },
Installment { plan: 24, amount: 347644 },
Installment { plan: 36, amount: 266292 },
Installment { plan: 48, amount: 226287 },
Installment { plan: 60, amount: 202809 },
Installment { plan: 72, amount: 187580 }
],
_config: {
installments: [ 18, 24, 36, 48, 60, 72 ],
interest_rate: 0.0158,
insurance: {
life: 0.0008,
unemployment: 0.0006,
vehicle: 0.05,
vehicle_iva: 0.19
},
charges: { movable_warranty: 200000, additive_charge_rate: 0.02 },
max_credit_amount: 40000000,
_defaultConfig: true
},
_errors: []
}Using a custom configuration object
import getSimulation from 'calculo-cuotas-francesconst CONFIG = {} // OBJETO DE CONFIGURACION
const opts = {
creditValue,
carValue,
config: CONFIG
}
const installments = getSimulation(opts)
// => Simulation {
...simulationObject,
_config: {
..CONFIG // CONFIGURACION PASADA POR PARAMETRO
}
_errors: [] // NO HUBO ERRORES
}NOTE: al pasar la propiedad config como un objeto de configuración personalizado, este objeto será validado internamente por el método validateConfigObject().
En caso de que el objeto pasado por parámetro contenga errores, se aplicará el objeto de configuración por defecto.
// =>
Simulation {
...simulationObject,
// CONFIGURACION PASADA POR PARAMETRO ,
_config: {
installments: [ 18, 24, 36, 48, 60, 72 ],
interest_rate: 0.0158,
insurance: {
life: 0.0008,
unemployment: 0.0006,
vehicle: 0.05,
vehicle_iva: 0.19
},
charges: {
movable_warranty: 200000,
additive_charge_rate: 0.02
},
max_credit_amount: 40000000,
_defaultConfig: true
},
_errors: [
{
name: 'ValidationError',
message: 'insurance.vehicle is a required field'
}
]
}Configuration object schema
De que tipo es cada propiedad y si es requerida
const configObjectSchema = yup.object().shape({
installments: yup.array().required(),
interest_rate: yup.number().required(),
insurance: yup.object().shape({
life: yup.number().required(),
unemployment: yup.number().required(),
vehicle: yup.number().required(),
vehicle_iva: yup.number().required(),
}),
charges: yup.object().shape({
movable_warranty: yup.number().required(),
additive_charge_rate: yup.number().required(),
}),
max_credit_amount: yup.number().required(),
_defaultConfig: yup.bool().required(),
})Running library
Podemos ejecutar la librería sobre node.js ejecutando el script por consola npm start y dentro de la misma, nos dará la opción de ingresar un monto inicial y un pie y así poder generar un plan de cuotas.
npm startRunning tests
npm test