Consolidar
This commit is contained in:
@ -22,19 +22,22 @@ class Moneda extends Model {
|
||||
$this->sufijo
|
||||
]));
|
||||
}
|
||||
public function cambio(\DateTime $fecha) {
|
||||
public function cambio(\DateTime $fecha, Moneda $moneda = null) {
|
||||
if ($moneda === null) {
|
||||
$moneda = $this->factory->find(Moneda::class)->one(1);
|
||||
}
|
||||
$cambio = $this->factory->find(TipoCambio::class)
|
||||
->where([['desde_id', $this->id], ['hasta_id', 1], ['fecha', $fecha->format('Y-m-d H:i:s')]])
|
||||
->where([['desde_id', $this->id], ['hasta_id', $moneda->id], ['fecha', $fecha->format('Y-m-d H:i:s')]])
|
||||
->one();
|
||||
if ($cambio === null) {
|
||||
$cambio = $this->factory->find(TipoCambio::class)
|
||||
->where([['hasta_id', $this->id], ['desde_id', 1], ['fecha', $fecha->format('Y-m-d H:i:s')]])
|
||||
->where([['hasta_id', $this->id], ['desde_id', $moneda->id], ['fecha', $fecha->format('Y-m-d H:i:s')]])
|
||||
->one();
|
||||
}
|
||||
return $cambio;
|
||||
}
|
||||
public function cambiar(\DateTime $fecha, float $valor) {
|
||||
$cambio = $this->cambio($fecha);
|
||||
public function cambiar(\DateTime $fecha, float $valor, Moneda $moneda = null) {
|
||||
$cambio = $this->cambio($fecha, $moneda);
|
||||
if (!$cambio) {
|
||||
return $valor;
|
||||
}
|
||||
|
Reference in New Issue
Block a user