move 7c78708 logic from transformer to controller

This commit is contained in:
Florian Dupret 2020-06-16 18:02:48 +02:00
parent 7c78708865
commit 16a511cf79
2 changed files with 4 additions and 3 deletions

View File

@ -212,6 +212,8 @@ class BillController extends Controller
$bills = $unfiltered->map( $bills = $unfiltered->map(
function (Bill $bill) use ($transformer, $defaultCurrency) { function (Bill $bill) use ($transformer, $defaultCurrency) {
$return = $transformer->transform($bill); $return = $transformer->transform($bill);
$nextExpectedMatch = new Carbon($return['next_expected_match']);
$return['next_expected_match_diff'] = $nextExpectedMatch->isToday() ? trans('firefly.today') : $nextExpectedMatch->diffForHumans(today(), Carbon::DIFF_RELATIVE_TO_NOW);
$currency = $bill->transactionCurrency ?? $defaultCurrency; $currency = $bill->transactionCurrency ?? $defaultCurrency;
$return['currency_id'] = $currency->id; $return['currency_id'] = $currency->id;
$return['currency_name'] = $currency->name; $return['currency_name'] = $currency->name;

View File

@ -83,8 +83,7 @@ class BillTransformer extends AbstractTransformer
'skip' => (int)$bill->skip, 'skip' => (int)$bill->skip,
'active' => $bill->active, 'active' => $bill->active,
'notes' => $notes, 'notes' => $notes,
'next_expected_match' => $paidData['next_expected_match']->format('Y-m-d'), 'next_expected_match' => $paidData['next_expected_match'],
'next_expected_match_diff'=> $paidData['next_expected_match']->isToday() ? trans('firefly.today') : $paidData['next_expected_match']->diffForHumans(Carbon::today(), Carbon::DIFF_RELATIVE_TO_NOW),
'pay_dates' => $payDates, 'pay_dates' => $payDates,
'paid_dates' => $paidData['paid_dates'], 'paid_dates' => $paidData['paid_dates'],
'links' => [ 'links' => [
@ -217,7 +216,7 @@ class BillTransformer extends AbstractTransformer
} }
$result = [ $result = [
'paid_dates' => $result, 'paid_dates' => $result,
'next_expected_match' => $nextMatch, 'next_expected_match' => $nextMatch->format('Y-m-d'),
]; ];
Log::debug('Result', $result); Log::debug('Result', $result);