Skip to content

Firefly III: a personal finances manager

Fix storage bug in #845

James Cole38bb07475160
diff --git a/app/Import/Object/ImportBill.php b/app/Import/Object/ImportBill.php
index 1760b33126..c85c755f05 100644
--- a/app/Import/Object/ImportBill.php
+++ b/app/Import/Object/ImportBill.php
@@ -17,6 +17,7 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
+use Steam;
/**
* Class ImportBill
@@ -26,6 +27,8 @@ use Log;
class ImportBill
{
+ /** @var string */
+ private $amount = '1';
/** @var Bill */
private $bill;
/** @var array */
@@ -59,6 +62,14 @@ class ImportBill
return $this->bill;
}
+ /**
+ * @param string $amount
+ */
+ public function setAmount(string $amount)
+ {
+ $this->amount = Steam::positive($amount);
+ }
+
/**
* @param array $id
*/
@@ -220,12 +231,22 @@ class ImportBill
return true;
}
- Log::debug('Found no bill so must create one ourselves.');
-
$data = [
- 'name' => $name,
+ 'name' => $name,
+ 'match' => $name,
+ 'amount_min' => bcmul($this->amount, '0.9'),
+ 'amount_max' => bcmul($this->amount, '1.1'),
+ 'user_id' => $this->user->id,
+ 'date' => date('Y-m-d'),
+ 'repeat_freq' => 'monthly',
+ 'skip' => '0',
+ 'automatch' => '0',
+ 'active' => '1',
];
+ Log::debug('Found no bill so must create one ourselves. Assume default values.', $data);
+
+
$this->bill = $this->repository->store($data);
Log::debug(sprintf('Successfully stored new bill #%d: %s', $this->bill->id, $this->bill->name));
diff --git a/app/Import/Storage/ImportStorage.php b/app/Import/Storage/ImportStorage.php
index 66ba023c17..75332a6d47 100644
--- a/app/Import/Storage/ImportStorage.php
+++ b/app/Import/Storage/ImportStorage.php
@@ -173,6 +173,10 @@ class ImportStorage
// store meta object things:
$this->storeCategory($journal, $importJournal->category->getCategory());
$this->storeBudget($journal, $importJournal->budget->getBudget());
+
+ // to save bill, also give it the amount:
+ $importJournal->bill->setAmount($amount);
+
$this->storeBill($journal, $importJournal->bill->getBill());
$this->storeMeta($journal, $importJournal->metaDates);
$journal->setMeta('notes', $importJournal->notes);