mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Updates to bill code for #1029
This commit is contained in:
@@ -42,9 +42,39 @@ class BillLine
|
||||
protected $min;
|
||||
/** @var Carbon */
|
||||
private $lastHitDate;
|
||||
/** @var Carbon */
|
||||
private $payDate;
|
||||
/** @var Carbon */
|
||||
private $endOfPayDate;
|
||||
/** @var int */
|
||||
private $transactionJournalId;
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getPayDate(): Carbon
|
||||
{
|
||||
return $this->payDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getEndOfPayDate(): Carbon
|
||||
{
|
||||
return $this->endOfPayDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $endOfPayDate
|
||||
*/
|
||||
public function setEndOfPayDate(Carbon $endOfPayDate): void
|
||||
{
|
||||
$this->endOfPayDate = $endOfPayDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* BillLine constructor.
|
||||
*/
|
||||
@@ -172,4 +202,12 @@ class BillLine
|
||||
{
|
||||
$this->hit = $hit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $payDate
|
||||
*/
|
||||
public function setPayDate(Carbon $payDate): void
|
||||
{
|
||||
$this->payDate = $payDate;
|
||||
}
|
||||
}
|
||||
|
@@ -71,34 +71,43 @@ class ReportHelper implements ReportHelperInterface
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$bills = $repository->getBillsForAccounts($accounts);
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->setBills($bills);
|
||||
$journals = $collector->getJournals();
|
||||
|
||||
$collection = new BillCollection;
|
||||
$collection->setStartDate($start);
|
||||
$collection->setEndDate($end);
|
||||
|
||||
/** @var Bill $bill */
|
||||
foreach ($bills as $bill) {
|
||||
$billLine = new BillLine;
|
||||
$billLine->setBill($bill);
|
||||
$billLine->setMin(strval($bill->amount_min));
|
||||
$billLine->setMax(strval($bill->amount_max));
|
||||
$billLine->setHit(false);
|
||||
$entry = $journals->filter(
|
||||
function (Transaction $transaction) use ($bill) {
|
||||
return $transaction->bill_id === $bill->id;
|
||||
$expectedDates = $repository->getPayDatesInRange($bill, $start, $end);
|
||||
foreach($expectedDates as $payDate) {
|
||||
$endOfPayPeriod = app('navigation')->endOfX($payDate, $bill->repeat_freq, null);
|
||||
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($payDate, $endOfPayPeriod)->setBills($bills);
|
||||
$journals = $collector->getJournals();
|
||||
|
||||
$billLine = new BillLine;
|
||||
$billLine->setBill($bill);
|
||||
$billLine->setPayDate($payDate);
|
||||
$billLine->setEndOfPayDate($endOfPayPeriod);
|
||||
$billLine->setMin(strval($bill->amount_min));
|
||||
$billLine->setMax(strval($bill->amount_max));
|
||||
$billLine->setHit(false);
|
||||
$entry = $journals->filter(
|
||||
function (Transaction $transaction) use ($bill) {
|
||||
return $transaction->bill_id === $bill->id;
|
||||
}
|
||||
);
|
||||
$first = $entry->first();
|
||||
if (null !== $first) {
|
||||
$billLine->setTransactionJournalId($first->id);
|
||||
$billLine->setAmount($first->transaction_amount);
|
||||
$billLine->setLastHitDate($first->date);
|
||||
$billLine->setHit(true);
|
||||
}
|
||||
if ($billLine->isActive() || $billLine->isHit()) {
|
||||
$collection->addBill($billLine);
|
||||
}
|
||||
);
|
||||
$first = $entry->first();
|
||||
if (null !== $first) {
|
||||
$billLine->setTransactionJournalId($first->id);
|
||||
$billLine->setAmount($first->transaction_amount);
|
||||
$billLine->setLastHitDate($first->date);
|
||||
$billLine->setHit(true);
|
||||
}
|
||||
if ($billLine->isActive() || $billLine->isHit()) {
|
||||
$collection->addBill($billLine);
|
||||
}
|
||||
}
|
||||
$collection->filterBills();
|
||||
|
Reference in New Issue
Block a user