mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Move code to repository.
This commit is contained in:
		| @@ -45,9 +45,8 @@ class FrontpageController extends Controller | ||||
|         $info = []; | ||||
|         /** @var PiggyBank $piggyBank */ | ||||
|         foreach ($set as $piggyBank) { | ||||
|             $rep    = $piggyBank->currentRelevantRep(); | ||||
|             $amount = strval($rep->currentamount); | ||||
|             if (null !== $rep->id && 1 === bccomp($amount, '0')) { | ||||
|             $amount = $repository->getCurrentAmount($piggyBank); | ||||
|             if (1 === bccomp($amount, '0')) { | ||||
|                 // percentage! | ||||
|                 $pct = round(($amount / $piggyBank->targetamount) * 100); | ||||
|  | ||||
|   | ||||
| @@ -67,12 +67,12 @@ class PiggyBankController extends Controller | ||||
|      * | ||||
|      * @return View | ||||
|      */ | ||||
|     public function add(PiggyBank $piggyBank) | ||||
|     public function add(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository) | ||||
|     { | ||||
|         /** @var Carbon $date */ | ||||
|         $date          = session('end', Carbon::now()->endOfMonth()); | ||||
|         $leftOnAccount = $piggyBank->leftOnAccount($date); | ||||
|         $savedSoFar    = $piggyBank->currentRelevantRep()->currentamount ?? '0'; | ||||
|         $savedSoFar    = $repository->getCurrentAmount($piggyBank); | ||||
|         $leftToSave    = bcsub($piggyBank->targetamount, $savedSoFar); | ||||
|         $maxAmount     = min($leftOnAccount, $leftToSave); | ||||
|  | ||||
| @@ -86,12 +86,12 @@ class PiggyBankController extends Controller | ||||
|      * | ||||
|      * @return View | ||||
|      */ | ||||
|     public function addMobile(PiggyBank $piggyBank) | ||||
|     public function addMobile(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository) | ||||
|     { | ||||
|         /** @var Carbon $date */ | ||||
|         $date          = session('end', Carbon::now()->endOfMonth()); | ||||
|         $leftOnAccount = $piggyBank->leftOnAccount($date); | ||||
|         $savedSoFar    = $piggyBank->currentRelevantRep()->currentamount ?? '0'; | ||||
|         $savedSoFar    = $repository->getCurrentAmount($piggyBank); | ||||
|         $leftToSave    = bcsub($piggyBank->targetamount, $savedSoFar); | ||||
|         $maxAmount     = min($leftOnAccount, $leftToSave); | ||||
|  | ||||
| @@ -212,7 +212,8 @@ class PiggyBankController extends Controller | ||||
|         Log::debug('Looping piggues'); | ||||
|         /** @var PiggyBank $piggyBank */ | ||||
|         foreach ($collection as $piggyBank) { | ||||
|             $piggyBank->savedSoFar = $piggyBank->currentRelevantRep()->currentamount ?? '0'; | ||||
|  | ||||
|             $piggyBank->savedSoFar = $piggyRepository->getCurrentAmount($piggyBank); | ||||
|             $piggyBank->percentage = 0 !== bccomp('0', $piggyBank->savedSoFar) ? intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100) : 0; | ||||
|             $piggyBank->leftToSave = bcsub($piggyBank->targetamount, strval($piggyBank->savedSoFar)); | ||||
|             $piggyBank->percentage = $piggyBank->percentage > 100 ? 100 : $piggyBank->percentage; | ||||
|   | ||||
| @@ -56,7 +56,7 @@ class PiggyBank extends Model | ||||
|     /** @var array */ | ||||
|     protected $dates = ['startdate', 'targetdate']; | ||||
|     /** @var array */ | ||||
|     protected $fillable = ['name', 'account_id', 'order', 'targetamount', 'startdate', 'targetdate']; | ||||
|     protected $fillable = ['name', 'account_id', 'order', 'targetamount', 'startdate', 'targetdate', 'active']; | ||||
|     /** @var array */ | ||||
|     protected $hidden = ['targetamount_encrypted', 'encrypted']; | ||||
|  | ||||
|   | ||||
| @@ -163,6 +163,24 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface | ||||
|         return new PiggyBank(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get current amount saved in piggy bank. | ||||
|      * | ||||
|      * @param PiggyBank $piggyBank | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getCurrentAmount(PiggyBank $piggyBank): string | ||||
|     { | ||||
|         /** @var PiggyBankRepetition $rep */ | ||||
|         $rep = $piggyBank->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']); | ||||
|         if (null === $rep) { | ||||
|             return '0'; | ||||
|         } | ||||
|  | ||||
|         return strval($rep->currentamount); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param PiggyBank $piggyBank | ||||
|      * | ||||
|   | ||||
| @@ -102,6 +102,15 @@ interface PiggyBankRepositoryInterface | ||||
|      */ | ||||
|     public function find(int $piggyBankid): PiggyBank; | ||||
|  | ||||
|     /** | ||||
|      * Get current amount saved in piggy bank. | ||||
|      * | ||||
|      * @param PiggyBank $piggyBank | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getCurrentAmount(PiggyBank $piggyBank): string; | ||||
|  | ||||
|     /** | ||||
|      * Get all events. | ||||
|      * | ||||
|   | ||||
		Reference in New Issue
	
	Block a user