Small update to frontend and associated code.

This commit is contained in:
James Cole
2022-06-05 20:02:43 +02:00
parent 6b2619c5cc
commit 9c08b9f1d3
102 changed files with 974 additions and 519 deletions

View File

@@ -85,6 +85,27 @@ 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.
*/
@@ -255,8 +276,8 @@ class BillRepository implements BillRepositoryInterface
*
* @param Carbon $start
* @param Carbon $end
*
* @return string
* @deprecated
*/
public function getBillsPaidInRange(Carbon $start, Carbon $end): string
{
@@ -291,11 +312,11 @@ class BillRepository implements BillRepositoryInterface
/**
* 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
{
@@ -323,8 +344,8 @@ class BillRepository implements BillRepositoryInterface
*
* @param Carbon $start
* @param Carbon $end
*
* @return string
* @deprecated
*/
public function getBillsUnpaidInRange(Carbon $start, Carbon $end): string
{
@@ -358,7 +379,6 @@ class BillRepository implements BillRepositoryInterface
* @param Carbon $end
*
* @return Collection
* @throws JsonException
*/
public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection
{
@@ -420,8 +440,8 @@ class BillRepository implements BillRepositoryInterface
*
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @deprecated
*/
public function getBillsUnpaidInRangePerCurrency(Carbon $start, Carbon $end): array
{
@@ -449,6 +469,66 @@ class BillRepository implements BillRepositoryInterface
return $return;
}
/**
* @inheritDoc
*/
public function sumUnpaidInRange(Carbon $start, Carbon $end): array
{
$bills = $this->getActiveBills();
$return = [];
/** @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) {
$currency = $bill->transactionCurrency;
$average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2');
$return[$currency->id] = $return[$currency->id] ?? [
'id' => (string) $currency->id,
'name' => $currency->name,
'symbol' => $currency->symbol,
'code' => $currency->code,
'decimal_places' => $currency->decimal_places,
'sum' => '0',
];
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], bcmul($average, (string) $total));
}
}
return $return;
}
/**
* @inheritDoc
*/
public function sumPaidInRange(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.*']);
$currency = $bill->transactionCurrency;
if ($set->count() > 0) {
$journalIds = $set->pluck('id')->toArray();
$amount = (string) Transaction::whereIn('transaction_journal_id', $journalIds)->where('amount', '<', 0)->sum('amount');
$return[$currency->id] = $return[$currency->id] ?? [
'id' => (string) $currency->id,
'name' => $currency->name,
'symbol' => $currency->symbol,
'code' => $currency->code,
'decimal_places' => $currency->decimal_places,
'sum' => '0',
];
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount);
}
}
return $return;
}
/**
* Get all bills with these ID's.
*

View File

@@ -43,6 +43,24 @@ interface BillRepositoryInterface
*/
public function billEndsWith(string $query, int $limit): Collection;
/**
* Collect multi-currency of sum of bills yet to pay.
*
* @param Carbon $start
* @param Carbon $end
* @return array
*/
public function sumUnpaidInRange(Carbon $start, Carbon $end): array;
/**
* Collect multi-currency of sum of bills already paid.
*
* @param Carbon $start
* @param Carbon $end
* @return array
*/
public function sumPaidInRange(Carbon $start, Carbon $end): array;
/**
* @param string $query
* @param int $limit
@@ -51,6 +69,16 @@ 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
* @deprecated
* @return Collection
*/
public function collectBillsUnpaidInRange(Carbon $start, Carbon $end): Collection;
/**
* Add correct order to bills.
*/
@@ -126,42 +154,42 @@ interface BillRepositoryInterface
/**
* 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;