mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
All kinds of new code, especially for the piggy banks.
This commit is contained in:
@@ -27,6 +27,37 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
$this->setUser(\Auth::user());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Ardent $model
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update(Ardent $model, array $data)
|
||||
{
|
||||
$model->name = $data['name'];
|
||||
$model->active = isset($data['active']) ? intval($data['active']) : 0;
|
||||
$model->save();
|
||||
|
||||
if (isset($data['openingbalance']) && isset($data['openingbalancedate'])) {
|
||||
$openingBalance = $this->openingBalanceTransaction($model);
|
||||
|
||||
$openingBalance->date = new Carbon($data['openingbalancedate']);
|
||||
$openingBalance->save();
|
||||
$amount = floatval($data['openingbalance']);
|
||||
/** @var \Transaction $transaction */
|
||||
foreach ($openingBalance->transactions as $transaction) {
|
||||
if ($transaction->account_id == $model->id) {
|
||||
$transaction->amount = $amount;
|
||||
} else {
|
||||
$transaction->amount = $amount * -1;
|
||||
}
|
||||
$transaction->save();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all asset accounts. Optional JSON based parameters.
|
||||
*
|
||||
|
Reference in New Issue
Block a user