Fix storage bug in #845

This commit is contained in:
James Cole 2017-09-15 06:26:09 +02:00
parent 519ca4b2af
commit 38bb074751
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 28 additions and 3 deletions

View File

@ -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));

View File

@ -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);