/**
  * @param Preference $preference
  *
  * @return TransactionCurrency
  */
 public function getCurrencyByPreference(Preference $preference)
 {
     $preferred = TransactionCurrency::whereCode($preference->data)->first();
     if (is_null($preferred)) {
         $preferred = TransactionCurrency::first();
     }
     return $preferred;
 }
Exemple #2
0
 /**
  * @return TransactionCurrency
  */
 public function convert()
 {
     if (isset($this->mapped[$this->index][$this->value])) {
         $currency = TransactionCurrency::find($this->mapped[$this->index][$this->value]);
     } else {
         $currency = TransactionCurrency::whereCode($this->value)->first();
     }
     return $currency;
 }
Exemple #3
0
 /**
  * @return array
  */
 public function process()
 {
     // fix currency
     if (is_null($this->data['currency'])) {
         $currencyPreference = Preferences::get('currencyPreference', env('DEFAULT_CURRENCY', 'EUR'));
         $this->data['currency'] = TransactionCurrency::whereCode($currencyPreference->data)->first();
     }
     return $this->data;
 }
Exemple #4
0
 /**
  *
  */
 protected function createPiggyBankEvent()
 {
     // piggy bank event
     // add money to this piggy bank
     // create a piggy bank event to match:
     $checking = $this->findAccount('Checking account');
     $savings = $this->findAccount('Savings account');
     $transfer = TransactionType::whereType('Transfer')->first();
     $euro = TransactionCurrency::whereCode('EUR')->first();
     $groceries = $this->findBudget('Groceries');
     $house = $this->findCategory('House');
     $piggyBank = $this->findPiggyBank('New camera');
     $intoPiggy = $this->createJournal(['from' => $checking, 'to' => $savings, 'amount' => 100, 'transactionType' => $transfer, 'description' => 'Money for piggy', 'date' => $this->yaeom, 'transactionCurrency' => $euro, 'category' => $house, 'budget' => $groceries]);
     PiggyBankEvent::create(['piggy_bank_id' => $piggyBank->id, 'transaction_journal_id' => $intoPiggy->id, 'date' => $this->yaeom, 'amount' => 100]);
 }
Exemple #5
0
 /**
  * @return mixed|static
  */
 public function getDefaultCurrency()
 {
     $cache = new CacheProperties();
     $cache->addProperty('getDefaultCurrency');
     if ($cache->has()) {
         return $cache->get();
     }
     $currencyPreference = Prefs::get('currencyPreference', 'EUR');
     $currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
     $cache->store($currency);
     return $currency;
 }
 /**
  * @covers FireflyIII\Support\Amount::getDefaultCurrency
  */
 public function testGetDefaultCurrency()
 {
     // will the the euro:
     $eur = TransactionCurrency::whereCode('EUR')->first();
     $result = $this->object->getDefaultCurrency();
     $this->assertEquals($eur->id, $result->id);
 }
Exemple #7
0
 /**
  * @return mixed|static
  */
 public function getDefaultCurrency()
 {
     $currencyPreference = Prefs::get('currencyPreference', 'EUR');
     $currency = TransactionCurrency::whereCode($currencyPreference->data)->first();
     return $currency;
 }