Esempio n. 1
0
 /**
  * @param PiggyBankRepositoryInterface $repository
  * @param PiggyBank                    $piggyBank
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postRemove(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
 {
     $amount = round(Input::get('amount'), 2);
     bcscale(2);
     $savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
     if ($amount <= $savedSoFar) {
         $repetition = $piggyBank->currentRelevantRep();
         $repetition->currentamount = bcsub($repetition->currentamount, $amount);
         $repetition->save();
         // create event
         $repository->createEvent($piggyBank, $amount * -1);
         Session::flash('success', 'Removed ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".');
         Preferences::mark();
     } else {
         Session::flash('error', 'Could not remove ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".');
     }
     return redirect(route('piggy-banks.index'));
 }
 /**
  * @param PiggyBankRepositoryInterface $repository
  * @param PiggyBank                    $piggyBank
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postRemove(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
 {
     $amount = strval(round(Input::get('amount'), 2));
     $savedSoFar = $piggyBank->currentRelevantRep()->currentamount;
     if ($amount <= $savedSoFar) {
         $repetition = $piggyBank->currentRelevantRep();
         $repetition->currentamount = bcsub($repetition->currentamount, $amount);
         $repetition->save();
         // create event
         $repository->createEvent($piggyBank, bcmul($amount, '-1'));
         Session::flash('success', strval(trans('firefly.removed_amount_from_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));
         Preferences::mark();
         return redirect(route('piggy-banks.index'));
     }
     Session::flash('error', strval(trans('firefly.cannot_remove_from_piggy', ['amount' => Amount::format($amount, false), 'name' => e($piggyBank->name)])));
     return redirect(route('piggy-banks.index'));
 }