示例#1
0
 /**
  * This method generates a full report for the given period on all
  * the users bills and their payments.
  *
  * Excludes bills which have not had a payment on the mentioned accounts.
  *
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return BillCollection
  */
 public function getBillReport(Carbon $start, Carbon $end, Collection $accounts)
 {
     /** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
     $repository = app('FireflyIII\\Repositories\\Bill\\BillRepositoryInterface');
     $bills = $repository->getBillsForAccounts($accounts);
     $journals = $repository->getAllJournalsInRange($bills, $start, $end);
     $collection = new BillCollection();
     /** @var Bill $bill */
     foreach ($bills as $bill) {
         $billLine = new BillLine();
         $billLine->setBill($bill);
         $billLine->setActive(intval($bill->active) == 1);
         $billLine->setMin($bill->amount_min);
         $billLine->setMax($bill->amount_max);
         // is hit in period?
         bcscale(2);
         $entry = $journals->filter(function (TransactionJournal $journal) use($bill) {
             return $journal->bill_id == $bill->id;
         });
         if (!is_null($entry->first())) {
             $billLine->setAmount($entry->first()->journalAmount);
             $billLine->setHit(true);
         } else {
             $billLine->setHit(false);
         }
         $collection->addBill($billLine);
     }
     return $collection;
 }
 /**
  * This method generates a full report for the given period on all
  * the users bills and their payments.
  *
  * Excludes bills which have not had a payment on the mentioned accounts.
  *
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return BillCollection
  */
 public function getBillReport(Carbon $start, Carbon $end, Collection $accounts) : BillCollection
 {
     /** @var BillRepositoryInterface $repository */
     $repository = app(BillRepositoryInterface::class);
     $bills = $repository->getBillsForAccounts($accounts);
     $journals = $repository->getAllJournalsInRange($bills, $start, $end);
     $collection = new BillCollection();
     /** @var Bill $bill */
     foreach ($bills as $bill) {
         $billLine = new BillLine();
         $billLine->setBill($bill);
         $billLine->setActive(intval($bill->active) === 1);
         $billLine->setMin(strval($bill->amount_min));
         $billLine->setMax(strval($bill->amount_max));
         $billLine->setHit(false);
         // is hit in period?
         $entry = $journals->filter(function (TransactionJournal $journal) use($bill) {
             return $journal->bill_id === $bill->id;
         });
         $first = $entry->first();
         if (!is_null($first)) {
             $billLine->setTransactionJournalId($first->id);
             $billLine->setAmount($first->journalAmount);
             $billLine->setHit(true);
         }
         if ($billLine->isActive()) {
             $collection->addBill($billLine);
         }
     }
     return $collection;
 }
 /**
  * This method generates a full report for the given period on all
  * the users bills and their payments.
  *
  * @param Carbon $start
  * @param Carbon $end
  *
  * @return BillCollection
  */
 public function getBillReport(Carbon $start, Carbon $end)
 {
     /** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
     $repository = app('FireflyIII\\Repositories\\Bill\\BillRepositoryInterface');
     $bills = $repository->getBills();
     $collection = new BillCollection();
     /** @var Bill $bill */
     foreach ($bills as $bill) {
         $billLine = new BillLine();
         $billLine->setBill($bill);
         $billLine->setActive(intval($bill->active) == 1);
         $billLine->setMin($bill->amount_min);
         $billLine->setMax($bill->amount_max);
         // is hit in period?
         bcscale(2);
         $set = $repository->getJournalsInRange($bill, $start, $end);
         if ($set->count() == 0) {
             $billLine->setHit(false);
         } else {
             $billLine->setHit(true);
             $amount = '0';
             foreach ($set as $entry) {
                 $amount = bcadd($amount, $entry->amount);
             }
             $billLine->setAmount($amount);
         }
         $collection->addBill($billLine);
     }
     return $collection;
 }