mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Simplify methods.
This commit is contained in:
@@ -328,8 +328,7 @@ trait ModifiesPiggyBanks
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
public function update(PiggyBank $piggyBank, array $data): PiggyBank
|
||||
{
|
||||
private function updateProperties(PiggyBank $piggyBank, array $data): PiggyBank {
|
||||
if (array_key_exists('name', $data) && '' !== $data['name']) {
|
||||
$piggyBank->name = $data['name'];
|
||||
}
|
||||
@@ -344,7 +343,18 @@ trait ModifiesPiggyBanks
|
||||
}
|
||||
$piggyBank->startdate = $data['startdate'] ?? $piggyBank->startdate;
|
||||
$piggyBank->save();
|
||||
return $piggyBank;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param array $data
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
public function update(PiggyBank $piggyBank, array $data): PiggyBank
|
||||
{
|
||||
$piggyBank = $this->updateProperties($piggyBank, $data);
|
||||
$this->updateNote($piggyBank, $data['notes'] ?? '');
|
||||
|
||||
// update the order of the piggy bank:
|
||||
|
@@ -69,6 +69,11 @@ class BillUpdateService
|
||||
$currency->enabled = true;
|
||||
$currency->save();
|
||||
|
||||
// new values
|
||||
$data['transaction_currency_name'] = $currency->name;
|
||||
$bill = $this->updateBillProperties($bill, $data);
|
||||
$bill->transaction_currency_id = $currency->id;
|
||||
$bill->save();
|
||||
// old values
|
||||
$oldData = [
|
||||
'name' => $bill->name,
|
||||
@@ -76,36 +81,7 @@ class BillUpdateService
|
||||
'amount_max' => $bill->amount_max,
|
||||
'transaction_currency_name' => $bill->transactionCurrency->name,
|
||||
];
|
||||
// new values
|
||||
$data['transaction_currency_name'] = $currency->name;
|
||||
|
||||
if (isset($data['name']) && '' !== (string)$data['name']) {
|
||||
$bill->name = $data['name'];
|
||||
}
|
||||
|
||||
if (isset($data['amount_min']) && '' !== (string)$data['amount_min']) {
|
||||
$bill->amount_min = $data['amount_min'];
|
||||
}
|
||||
if (isset($data['amount_max']) && '' !== (string)$data['amount_max']) {
|
||||
$bill->amount_max = $data['amount_max'];
|
||||
}
|
||||
if (isset($data['date']) && '' !== (string)$data['date']) {
|
||||
$bill->date = $data['date'];
|
||||
}
|
||||
if (isset($data['repeat_freq']) && '' !== (string)$data['repeat_freq']) {
|
||||
$bill->repeat_freq = $data['repeat_freq'];
|
||||
}
|
||||
if (isset($data['skip']) && '' !== (string)$data['skip']) {
|
||||
$bill->skip = $data['skip'];
|
||||
}
|
||||
if (isset($data['active']) && is_bool($data['active'])) {
|
||||
$bill->active = $data['active'];
|
||||
}
|
||||
|
||||
$bill->transaction_currency_id = $currency->id;
|
||||
$bill->match = 'EMPTY';
|
||||
$bill->automatch = true;
|
||||
$bill->save();
|
||||
|
||||
// update note:
|
||||
if (isset($data['notes'])) {
|
||||
@@ -132,6 +108,7 @@ class BillUpdateService
|
||||
$bill->objectGroups()->sync([$objectGroup->id]);
|
||||
$bill->save();
|
||||
}
|
||||
|
||||
return $bill;
|
||||
}
|
||||
// remove if name is empty. Should be overruled by ID.
|
||||
@@ -148,9 +125,10 @@ class BillUpdateService
|
||||
$bill->objectGroups()->sync([$objectGroup->id]);
|
||||
$bill->save();
|
||||
}
|
||||
|
||||
return $bill;
|
||||
}
|
||||
if(0 === $objectGroupId) {
|
||||
if (0 === $objectGroupId) {
|
||||
$bill->objectGroups()->sync([]);
|
||||
$bill->save();
|
||||
}
|
||||
@@ -252,4 +230,43 @@ class BillUpdateService
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param array $data
|
||||
*
|
||||
* @return Bill
|
||||
*/
|
||||
private function updateBillProperties(Bill $bill, array $data): Bill
|
||||
{
|
||||
|
||||
if (isset($data['name']) && '' !== (string)$data['name']) {
|
||||
$bill->name = $data['name'];
|
||||
}
|
||||
|
||||
if (isset($data['amount_min']) && '' !== (string)$data['amount_min']) {
|
||||
$bill->amount_min = $data['amount_min'];
|
||||
}
|
||||
if (isset($data['amount_max']) && '' !== (string)$data['amount_max']) {
|
||||
$bill->amount_max = $data['amount_max'];
|
||||
}
|
||||
if (isset($data['date']) && '' !== (string)$data['date']) {
|
||||
$bill->date = $data['date'];
|
||||
}
|
||||
if (isset($data['repeat_freq']) && '' !== (string)$data['repeat_freq']) {
|
||||
$bill->repeat_freq = $data['repeat_freq'];
|
||||
}
|
||||
if (isset($data['skip']) && '' !== (string)$data['skip']) {
|
||||
$bill->skip = $data['skip'];
|
||||
}
|
||||
if (isset($data['active']) && is_bool($data['active'])) {
|
||||
$bill->active = $data['active'];
|
||||
}
|
||||
|
||||
$bill->match = 'EMPTY';
|
||||
$bill->automatch = true;
|
||||
$bill->save();
|
||||
|
||||
return $bill;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user