|
|
|
|
@@ -60,17 +60,17 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
$paidData = $this->paidData($bill);
|
|
|
|
|
$payDates = $this->payDates($bill);
|
|
|
|
|
$currency = $bill->transactionCurrency;
|
|
|
|
|
$notes = $this->repository->getNoteText($bill);
|
|
|
|
|
$notes = '' === $notes ? null : $notes;
|
|
|
|
|
$notes = $this->repository->getNoteText($bill);
|
|
|
|
|
$notes = '' === $notes ? null : $notes;
|
|
|
|
|
$this->repository->setUser($bill->user);
|
|
|
|
|
|
|
|
|
|
$objectGroupId = null;
|
|
|
|
|
$objectGroupId = null;
|
|
|
|
|
$objectGroupOrder = null;
|
|
|
|
|
$objectGroupTitle = null;
|
|
|
|
|
/** @var ObjectGroup $objectGroup */
|
|
|
|
|
$objectGroup = $bill->objectGroups->first();
|
|
|
|
|
if (null !== $objectGroup) {
|
|
|
|
|
$objectGroupId = (int)$objectGroup->id;
|
|
|
|
|
$objectGroupId = (int)$objectGroup->id;
|
|
|
|
|
$objectGroupOrder = (int)$objectGroup->order;
|
|
|
|
|
$objectGroupTitle = $objectGroup->title;
|
|
|
|
|
}
|
|
|
|
|
@@ -78,7 +78,7 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
$paidDataFormatted = [];
|
|
|
|
|
$payDatesFormatted = [];
|
|
|
|
|
foreach ($paidData['paid_dates'] as $object) {
|
|
|
|
|
$object['date'] = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone'))->toAtomString();
|
|
|
|
|
$object['date'] = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone'))->toAtomString();
|
|
|
|
|
$paidDataFormatted[] = $object;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -98,40 +98,40 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
|
|
|
|
|
$current = $payDatesFormatted[0] ?? null;
|
|
|
|
|
if (null !== $current && !$temp->isToday()) {
|
|
|
|
|
$temp2 = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
|
|
|
|
|
$temp2 = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
|
|
|
|
|
$nextExpectedMatchDiff = $temp2->diffForHumans(today(config('app.timezone')), CarbonInterface::DIFF_RELATIVE_TO_NOW);
|
|
|
|
|
}
|
|
|
|
|
unset($temp, $temp2);
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'id' => (int)$bill->id,
|
|
|
|
|
'created_at' => $bill->created_at->toAtomString(),
|
|
|
|
|
'updated_at' => $bill->updated_at->toAtomString(),
|
|
|
|
|
'currency_id' => (string)$bill->transaction_currency_id,
|
|
|
|
|
'currency_code' => $currency->code,
|
|
|
|
|
'currency_symbol' => $currency->symbol,
|
|
|
|
|
'currency_decimal_places' => (int)$currency->decimal_places,
|
|
|
|
|
'name' => $bill->name,
|
|
|
|
|
'amount_min' => app('steam')->bcround($bill->amount_min, $currency->decimal_places),
|
|
|
|
|
'amount_max' => app('steam')->bcround($bill->amount_max, $currency->decimal_places),
|
|
|
|
|
'date' => $bill->date->toAtomString(),
|
|
|
|
|
'end_date' => $bill->end_date?->toAtomString(),
|
|
|
|
|
'extension_date' => $bill->extension_date?->toAtomString(),
|
|
|
|
|
'repeat_freq' => $bill->repeat_freq,
|
|
|
|
|
'skip' => (int)$bill->skip,
|
|
|
|
|
'active' => $bill->active,
|
|
|
|
|
'order' => (int)$bill->order,
|
|
|
|
|
'notes' => $notes,
|
|
|
|
|
'object_group_id' => $objectGroupId ? (string)$objectGroupId : null,
|
|
|
|
|
'object_group_order' => $objectGroupOrder,
|
|
|
|
|
'object_group_title' => $objectGroupTitle,
|
|
|
|
|
'id' => (int)$bill->id,
|
|
|
|
|
'created_at' => $bill->created_at->toAtomString(),
|
|
|
|
|
'updated_at' => $bill->updated_at->toAtomString(),
|
|
|
|
|
'currency_id' => (string)$bill->transaction_currency_id,
|
|
|
|
|
'currency_code' => $currency->code,
|
|
|
|
|
'currency_symbol' => $currency->symbol,
|
|
|
|
|
'currency_decimal_places' => (int)$currency->decimal_places,
|
|
|
|
|
'name' => $bill->name,
|
|
|
|
|
'amount_min' => app('steam')->bcround($bill->amount_min, $currency->decimal_places),
|
|
|
|
|
'amount_max' => app('steam')->bcround($bill->amount_max, $currency->decimal_places),
|
|
|
|
|
'date' => $bill->date->toAtomString(),
|
|
|
|
|
'end_date' => $bill->end_date?->toAtomString(),
|
|
|
|
|
'extension_date' => $bill->extension_date?->toAtomString(),
|
|
|
|
|
'repeat_freq' => $bill->repeat_freq,
|
|
|
|
|
'skip' => (int)$bill->skip,
|
|
|
|
|
'active' => $bill->active,
|
|
|
|
|
'order' => (int)$bill->order,
|
|
|
|
|
'notes' => $notes,
|
|
|
|
|
'object_group_id' => $objectGroupId ? (string)$objectGroupId : null,
|
|
|
|
|
'object_group_order' => $objectGroupOrder,
|
|
|
|
|
'object_group_title' => $objectGroupTitle,
|
|
|
|
|
|
|
|
|
|
// these fields need work:
|
|
|
|
|
'next_expected_match' => $nextExpectedMatch,
|
|
|
|
|
'next_expected_match' => $nextExpectedMatch,
|
|
|
|
|
'next_expected_match_diff' => $nextExpectedMatchDiff,
|
|
|
|
|
'pay_dates' => $payDatesFormatted,
|
|
|
|
|
'paid_dates' => $paidDataFormatted,
|
|
|
|
|
'links' => [
|
|
|
|
|
'pay_dates' => $payDatesFormatted,
|
|
|
|
|
'paid_dates' => $paidDataFormatted,
|
|
|
|
|
'links' => [
|
|
|
|
|
[
|
|
|
|
|
'rel' => 'self',
|
|
|
|
|
'uri' => '/bills/' . $bill->id,
|
|
|
|
|
@@ -154,7 +154,7 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
app('log')->debug('parameters are NULL, return empty array');
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'paid_dates' => [],
|
|
|
|
|
'paid_dates' => [],
|
|
|
|
|
'next_expected_match' => null,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
@@ -162,7 +162,7 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
// 2023-07-18 this particular date is used to search for the last paid date.
|
|
|
|
|
// 2023-07-18 the cloned $searchDate is used to grab the correct transactions.
|
|
|
|
|
/** @var Carbon $start */
|
|
|
|
|
$start = clone $this->parameters->get('start');
|
|
|
|
|
$start = clone $this->parameters->get('start');
|
|
|
|
|
$searchStart = clone $start;
|
|
|
|
|
$start->subDay();
|
|
|
|
|
|
|
|
|
|
@@ -189,7 +189,7 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
/*
|
|
|
|
|
* Diff in months (or other period) between bill start and last paid date or $start.
|
|
|
|
|
*/
|
|
|
|
|
$steps = app('navigation')->diffInPeriods($bill->repeat_freq, $bill->skip, $start, $nextMatch);
|
|
|
|
|
$steps = app('navigation')->diffInPeriods($bill->repeat_freq, $bill->skip, $start, $nextMatch);
|
|
|
|
|
$nextMatch = app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $steps);
|
|
|
|
|
|
|
|
|
|
if ($nextMatch->lt($lastPaidDate)) {
|
|
|
|
|
@@ -213,16 +213,16 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
$result = [];
|
|
|
|
|
foreach ($set as $entry) {
|
|
|
|
|
$result[] = [
|
|
|
|
|
'transaction_group_id' => (int)$entry->transaction_group_id,
|
|
|
|
|
'transaction_group_id' => (int)$entry->transaction_group_id,
|
|
|
|
|
'transaction_journal_id' => (int)$entry->id,
|
|
|
|
|
'date' => $entry->date->format('Y-m-d'),
|
|
|
|
|
'date' => $entry->date->format('Y-m-d'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app('log')->debug(sprintf('Next match: %s', $nextMatch->toIso8601String()));
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'paid_dates' => $result,
|
|
|
|
|
'paid_dates' => $result,
|
|
|
|
|
'next_expected_match' => $nextMatch->format('Y-m-d'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
@@ -231,7 +231,7 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
* Returns the latest date in the set, or start when set is empty.
|
|
|
|
|
*
|
|
|
|
|
* @param Collection $dates
|
|
|
|
|
* @param Carbon $default
|
|
|
|
|
* @param Carbon $default
|
|
|
|
|
*
|
|
|
|
|
* @return Carbon
|
|
|
|
|
*/
|
|
|
|
|
@@ -265,7 +265,7 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
app('log')->debug(sprintf('Start: %s, end: %s', $this->parameters->get('start')->format('Y-m-d'), $this->parameters->get('end')->format('Y-m-d')));
|
|
|
|
|
$set = new Collection();
|
|
|
|
|
$set = new Collection();
|
|
|
|
|
$currentStart = clone $this->parameters->get('start');
|
|
|
|
|
// 2023-06-23 subDay to fix 7655
|
|
|
|
|
$currentStart->subDay();
|
|
|
|
|
@@ -303,7 +303,7 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
}
|
|
|
|
|
app('log')->debug(sprintf('Next expected match is %s', $nextExpectedMatch->format('Y-m-d')));
|
|
|
|
|
// add to set, if the date is ON or after the start parameter
|
|
|
|
|
if($nextExpectedMatch->gte($this->parameters->get('start'))) {
|
|
|
|
|
if ($nextExpectedMatch->gte($this->parameters->get('start'))) {
|
|
|
|
|
$set->push(clone $nextExpectedMatch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -334,7 +334,7 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
* Given a bill and a date, this method will tell you at which moment this bill expects its next
|
|
|
|
|
* transaction. That date must be AFTER $date as a sanity check.
|
|
|
|
|
*
|
|
|
|
|
* @param Bill $bill
|
|
|
|
|
* @param Bill $bill
|
|
|
|
|
* @param Carbon $date
|
|
|
|
|
*
|
|
|
|
|
* @return Carbon
|
|
|
|
|
@@ -349,7 +349,7 @@ class BillTransformer extends AbstractTransformer
|
|
|
|
|
return clone $start;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$steps = app('navigation')->diffInPeriods($bill->repeat_freq, $bill->skip, $start, $date);
|
|
|
|
|
$steps = app('navigation')->diffInPeriods($bill->repeat_freq, $bill->skip, $start, $date);
|
|
|
|
|
$result = clone $start;
|
|
|
|
|
if ($steps > 0) {
|
|
|
|
|
$steps = $steps - 1;
|
|
|
|
|
|