This commit is contained in:
James Cole 2018-12-21 15:42:40 +01:00
parent 75cc024e28
commit 922c8703f5
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 28 additions and 4 deletions

View File

@ -36,6 +36,8 @@ use Log;
*/ */
class BillFactory class BillFactory
{ {
use BillServiceTrait;
/** /**
* Constructor. * Constructor.
*/ */
@ -46,7 +48,6 @@ class BillFactory
} }
} }
use BillServiceTrait;
/** @var User */ /** @var User */
private $user; private $user;
@ -61,6 +62,12 @@ class BillFactory
$factory = app(TransactionCurrencyFactory::class); $factory = app(TransactionCurrencyFactory::class);
/** @var TransactionCurrency $currency */ /** @var TransactionCurrency $currency */
$currency = $factory->find((int)$data['currency_id'], (string)$data['currency_code']); $currency = $factory->find((int)$data['currency_id'], (string)$data['currency_code']);
if(null === $currency) {
// use default currency:
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
}
/** @var Bill $bill */ /** @var Bill $bill */
$bill = Bill::create( $bill = Bill::create(
[ [

View File

@ -23,7 +23,9 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Update; namespace FireflyIII\Services\Internal\Update;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Services\Internal\Support\BillServiceTrait; use FireflyIII\Services\Internal\Support\BillServiceTrait;
use Log; use Log;
/** /**
@ -52,12 +54,27 @@ class BillUpdateService
*/ */
public function update(Bill $bill, array $data): Bill public function update(Bill $bill, array $data): Bill
{ {
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
/** @var TransactionCurrency $currency */
$currency = $factory->find((int)$data['currency_id'], (string)$data['currency_code']);
if(null === $currency) {
// use default currency:
$currency = app('amount')->getDefaultCurrencyByUser($bill->user);
}
// enable the currency if it isn't.
$currency->enabled = true;
$currency->save();
$oldName = $bill->name; $oldName = $bill->name;
$bill->name = $data['name']; $bill->name = $data['name'];
$bill->amount_min = $data['amount_min']; $bill->amount_min = $data['amount_min'];
$bill->amount_max = $data['amount_max']; $bill->amount_max = $data['amount_max'];
$bill->date = $data['date']; $bill->date = $data['date'];
$bill->transaction_currency_id = $data['currency_id']; $bill->transaction_currency_id = $currency->id;
$bill->repeat_freq = $data['repeat_freq']; $bill->repeat_freq = $data['repeat_freq'];
$bill->skip = $data['skip']; $bill->skip = $data['skip'];
$bill->automatch = true; $bill->automatch = true;

View File

@ -213,8 +213,8 @@ class BillControllerTest extends TestCase
//calls for transaction matcher: //calls for transaction matcher:
// todo bad to do this: // todo bad to do this:
$matcher = $this->mock(TransactionMatcher::class); $matcher = $this->mock(TransactionMatcher::class);
$matcher->shouldReceive('setLimit')->once()->withArgs([100000]); $matcher->shouldReceive('setSearchLimit')->once()->withArgs([100000]);
$matcher->shouldReceive('setRange')->once()->withArgs([100000]); $matcher->shouldReceive('setTriggeredLimit')->once()->withArgs([100000]);
$matcher->shouldReceive('setRule')->once()->withArgs([Mockery::any()]); $matcher->shouldReceive('setRule')->once()->withArgs([Mockery::any()]);
$matcher->shouldReceive('findTransactionsByRule')->once()->andReturn(new Collection); $matcher->shouldReceive('findTransactionsByRule')->once()->andReturn(new Collection);