/**
  * @param $attribute
  *
  * @return bool
  */
 public function validateRuleTriggerValue($attribute) : bool
 {
     // get the index from a string like "rule-trigger-value.2".
     $parts = explode('.', $attribute);
     $index = $parts[count($parts) - 1];
     // loop all rule-triggers.
     // check if rule-value matches the thing.
     if (is_array($this->data['rule-trigger'])) {
         $name = $this->getRuleTriggerName($index);
         $value = $this->getRuleTriggerValue($index);
         // break on some easy checks:
         switch ($name) {
             case 'amount_less':
                 $result = is_numeric($value);
                 if ($result === false) {
                     return false;
                 }
                 break;
             case 'transaction_type':
                 $count = TransactionType::where('type', $value)->count();
                 if (!($count === 1)) {
                     return false;
                 }
                 break;
             case 'invalid':
                 return false;
         }
         // still a special case where the trigger is
         // triggered in such a way that it would trigger ANYTHING. We can check for such things
         // with function willmatcheverything
         // we know which class it is so dont bother checking that.
         $classes = Config::get('firefly.rule-triggers');
         /** @var TriggerInterface $class */
         $class = $classes[$name];
         return !$class::willMatchEverything($value);
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * @return TransactionType
  */
 protected function getTransactionType()
 {
     $transactionType = TransactionType::where('type', TransactionType::DEPOSIT)->first();
     if ($this->importData['amount'] < 0) {
         $transactionType = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
     }
     if (in_array($this->importData['opposing-account-object']->accountType->type, ['Asset account', 'Default account'])) {
         $transactionType = TransactionType::where('type', TransactionType::TRANSFER)->first();
     }
     return $transactionType;
 }
 /**
  * Store journal only, uncompleted, with attachments if necessary.
  *
  * @param array $data
  *
  * @return TransactionJournal
  */
 public function storeJournal(array $data) : TransactionJournal
 {
     // find transaction type.
     $transactionType = TransactionType::where('type', ucfirst($data['what']))->first();
     // store actual journal.
     $journal = new TransactionJournal(['user_id' => $data['user'], 'transaction_type_id' => $transactionType->id, 'transaction_currency_id' => $data['amount_currency_id_amount'], 'description' => $data['description'], 'completed' => 0, 'date' => $data['date']]);
     $result = $journal->save();
     if ($result) {
         return $journal;
     }
     return new TransactionJournal();
 }
Ejemplo n.º 4
0
 /**
  * @return TransactionType
  */
 protected function getTransactionType()
 {
     $transactionType = TransactionType::where('type', 'Deposit')->first();
     if ($this->importData['amount'] < 0) {
         $transactionType = TransactionType::where('type', 'Withdrawal')->first();
     }
     if (in_array($this->importData['opposing-account-object']->accountType->type, ['Asset account', 'Default account'])) {
         $transactionType = TransactionType::where('type', 'Transfer')->first();
     }
     return $transactionType;
 }
Ejemplo n.º 5
0
 /**
  * @param array $data
  *
  * @return TransactionJournal
  */
 public function store(array $data)
 {
     // find transaction type.
     $transactionType = TransactionType::where('type', ucfirst($data['what']))->first();
     // store actual journal.
     $journal = new TransactionJournal(['user_id' => $data['user'], 'transaction_type_id' => $transactionType->id, 'transaction_currency_id' => $data['amount_currency_id'], 'description' => $data['description'], 'completed' => 0, 'date' => $data['date']]);
     $journal->save();
     // store or get category
     if (strlen($data['category']) > 0) {
         $category = Category::firstOrCreateEncrypted(['name' => $data['category'], 'user_id' => $data['user']]);
         $journal->categories()->save($category);
     }
     // store or get budget
     if (intval($data['budget_id']) > 0) {
         /** @var \FireflyIII\Models\Budget $budget */
         $budget = Budget::find($data['budget_id']);
         $journal->budgets()->save($budget);
     }
     // store accounts (depends on type)
     list($from, $to) = $this->storeAccounts($transactionType, $data);
     // store accompanying transactions.
     Transaction::create(['account_id' => $from->id, 'transaction_journal_id' => $journal->id, 'amount' => $data['amount'] * -1]);
     Transaction::create(['account_id' => $to->id, 'transaction_journal_id' => $journal->id, 'amount' => $data['amount']]);
     $journal->completed = 1;
     $journal->save();
     // store tags
     if (isset($data['tags']) && is_array($data['tags'])) {
         $this->saveTags($journal, $data['tags']);
     }
     return $journal;
 }
Ejemplo n.º 6
0
 /**
  * @param $attribute
  *
  * @return bool
  */
 public function validateRuleTriggerValue($attribute)
 {
     // get the index from a string like "rule-trigger-value.2".
     $parts = explode('.', $attribute);
     $index = $parts[count($parts) - 1];
     // loop all rule-triggers.
     // check if rule-value matches the thing.
     if (is_array($this->data['rule-trigger'])) {
         $name = $this->getRuleTriggerName($index);
         $value = $this->getRuleTriggerValue($index);
         switch ($name) {
             default:
                 return true;
             case 'amount_less':
                 return is_numeric($value);
             case 'transaction_type':
                 $count = TransactionType::where('type', $value)->count();
                 return $count === 1;
             case 'invalid':
                 return false;
         }
     }
     return false;
 }