clean: remove deprecated methods and refactor as necessary.

This commit is contained in:
James Cole
2023-06-02 06:38:07 +02:00
parent 527f18c1e3
commit b72aa92e55
4 changed files with 38 additions and 252 deletions

View File

@@ -87,27 +87,6 @@ class BillRepository implements BillRepositoryInterface
return $search->take($limit)->get();
}
/**
* @inheritDoc
* @deprecated
*/
public function collectBillsUnpaidInRange(Carbon $start, Carbon $end): Collection
{
$bills = $this->getActiveBills();
$return = new Collection();
/** @var Bill $bill */
foreach ($bills as $bill) {
$dates = $this->getPayDatesInRange($bill, $start, $end);
$count = $bill->transactionJournals()->after($start)->before($end)->count();
$total = $dates->count() - $count;
if ($total > 0) {
$return->push($bill);
}
}
return $bills;
}
/**
* Correct order of piggies in case of issues.
*/
@@ -296,139 +275,6 @@ class BillRepository implements BillRepositoryInterface
->get($fields);
}
/**
* TODO unsure why this is deprecated.
*
* Get the total amount of money paid for the users active bills in the date range given.
* This amount will be negative (they're expenses). This method is equal to
* getBillsUnpaidInRange. So the debug comments are gone.
*
* @param Carbon $start
* @param Carbon $end
* @return string
* @deprecated
*/
public function getBillsPaidInRange(Carbon $start, Carbon $end): string
{
$bills = $this->getActiveBills();
$sum = '0';
/** @var Bill $bill */
foreach ($bills as $bill) {
/** @var Collection $set */
$set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']);
if ($set->count() > 0) {
$journalIds = $set->pluck('id')->toArray();
$amount = (string)Transaction::whereIn('transaction_journal_id', $journalIds)->where('amount', '<', 0)->sum('amount');
$sum = bcadd($sum, $amount);
//Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f', $amount, $sum));
}
}
return $sum;
}
/**
* TODO unsure why this is deprecated.
*
* Get the total amount of money paid for the users active bills in the date range given,
* grouped per currency.
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @deprecated
*/
public function getBillsPaidInRangePerCurrency(Carbon $start, Carbon $end): array
{
$bills = $this->getActiveBills();
$return = [];
/** @var Bill $bill */
foreach ($bills as $bill) {
/** @var Collection $set */
$set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']);
$currencyId = (int)$bill->transaction_currency_id;
if ($set->count() > 0) {
$journalIds = $set->pluck('id')->toArray();
$amount = (string)Transaction::whereIn('transaction_journal_id', $journalIds)->where('amount', '<', 0)->sum('amount');
$return[$currencyId] = $return[$currencyId] ?? '0';
$return[$currencyId] = bcadd($amount, $return[$currencyId]);
//Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f (currency %d)', $amount, $return[$currencyId], $currencyId));
}
}
return $return;
}
/**
* TODO unsure why this is deprecated.
*
* Get the total amount of money due for the users active bills in the date range given. This amount will be positive.
*
* @param Carbon $start
* @param Carbon $end
* @return string
* @deprecated
*/
public function getBillsUnpaidInRange(Carbon $start, Carbon $end): string
{
$bills = $this->getActiveBills();
$sum = '0';
/** @var Bill $bill */
foreach ($bills as $bill) {
//Log::debug(sprintf('Now at bill #%d (%s)', $bill->id, $bill->name));
$dates = $this->getPayDatesInRange($bill, $start, $end);
$count = $bill->transactionJournals()->after($start)->before($end)->count();
$total = $dates->count() - $count;
//Log::debug(sprintf('Dates = %d, journalCount = %d, total = %d', $dates->count(), $count, $total));
if ($total > 0) {
$average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2');
$multi = bcmul($average, (string)$total);
$sum = bcadd($sum, $multi);
//Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f', $multi, $sum));
}
}
return $sum;
}
/**
* TODO unsure why this is deprecated.
*
* Get the total amount of money due for the users active bills in the date range given.
*
* @param Carbon $start
* @param Carbon $end
* @return array
* @deprecated
*/
public function getBillsUnpaidInRangePerCurrency(Carbon $start, Carbon $end): array
{
$bills = $this->getActiveBills();
$return = [];
/** @var Bill $bill */
foreach ($bills as $bill) {
//Log::debug(sprintf('Now at bill #%d (%s)', $bill->id, $bill->name));
$dates = $this->getPayDatesInRange($bill, $start, $end);
$count = $bill->transactionJournals()->after($start)->before($end)->count();
$total = $dates->count() - $count;
$currencyId = (int)$bill->transaction_currency_id;
//Log::debug(sprintf('Dates = %d, journalCount = %d, total = %d', $dates->count(), $count, $total));
if ($total > 0) {
$average = bcdiv(bcadd((string)$bill->amount_max, (string)$bill->amount_min), '2');
$multi = bcmul($average, (string)$total);
$return[$currencyId] = $return[$currencyId] ?? '0';
$return[$currencyId] = bcadd($return[$currencyId], $multi);
//Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f (for currency %d)', $multi, $return[$currencyId], $currencyId));
}
}
return $return;
}
/**
* Get all bills with these ID's.
*

View File

@@ -52,16 +52,6 @@ interface BillRepositoryInterface
*/
public function billStartsWith(string $query, int $limit): Collection;
/**
* Get the total amount of money due for the users active bills in the date range given.
*
* @param Carbon $start
* @param Carbon $end
* @return Collection
* @deprecated
*/
public function collectBillsUnpaidInRange(Carbon $start, Carbon $end): Collection;
/**
* Add correct order to bills.
*/
@@ -135,47 +125,6 @@ interface BillRepositoryInterface
*/
public function getBillsForAccounts(Collection $accounts): Collection;
/**
* Get the total amount of money paid for the users active bills in the date range given.
* @param Carbon $start
* @param Carbon $end
*
* @return string
* @deprecated
*/
public function getBillsPaidInRange(Carbon $start, Carbon $end): string;
/**
* Get the total amount of money paid for the users active bills in the date range given,
* grouped per currency.
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @deprecated
*/
public function getBillsPaidInRangePerCurrency(Carbon $start, Carbon $end): array;
/**
* Get the total amount of money due for the users active bills in the date range given.
* @param Carbon $start
* @param Carbon $end
*
* @return string
* @deprecated
*/
public function getBillsUnpaidInRange(Carbon $start, Carbon $end): string;
/**
* Get the total amount of money due for the users active bills in the date range given.
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @deprecated
*/
public function getBillsUnpaidInRangePerCurrency(Carbon $start, Carbon $end): array;
/**
* Get all bills with these ID's.
*