jimmyfish

Active balance old

Oct 21st, 2020
1,070
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. public function getActiveBalance($buildId)
  4.     {
  5.         $activeBalance = $this->buildPointHistoryRepository->getActiveBalance($buildId);
  6.  
  7.         list($credits, $debits) = $activeBalance->partition(function ($balance) {
  8.             return $balance->b_point_hits_action === "Credit";
  9.         });
  10.  
  11.         $creditAmount = $credits->map(function ($credit) {
  12.             $actualAmount = $credit->b_point_hits_amount;
  13.             $fee = explode('-', Str::slug($credit->b_point_hits_description));
  14.  
  15.             return $actualAmount + $fee[count($fee) - 1];
  16.         });
  17.  
  18.         $debitAmount = $debits->map(function ($debit) {
  19.             return $debit->b_point_hits_amount;
  20.         });
  21.  
  22.         return $debitAmount->sum() - $creditAmount->sum();
  23.     }
RAW Paste Data