James Cole
2024-11-02 05:14:03 +01:00
parent 40de147611
commit 4b27ab38f8
3 changed files with 17 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
@@ -167,12 +168,14 @@ class TransactionJournal extends Model
public function scopeAfter(EloquentBuilder $query, Carbon $date): EloquentBuilder public function scopeAfter(EloquentBuilder $query, Carbon $date): EloquentBuilder
{ {
return $query->where('transaction_journals.date', '>=', $date->format('Y-m-d 00:00:00')); Log::debug(sprintf('scopeAfter("%s")', $date->format('Y-m-d H:i:s')));
return $query->where('transaction_journals.date', '>=', $date->format('Y-m-d H:i:s'));
} }
public function scopeBefore(EloquentBuilder $query, Carbon $date): EloquentBuilder public function scopeBefore(EloquentBuilder $query, Carbon $date): EloquentBuilder
{ {
return $query->where('transaction_journals.date', '<=', $date->format('Y-m-d 00:00:00')); Log::debug(sprintf('scopeBefore("%s")', $date->format('Y-m-d H:i:s')));
return $query->where('transaction_journals.date', '<=', $date->format('Y-m-d H:i:s'));
} }
public function scopeTransactionTypes(EloquentBuilder $query, array $types): void public function scopeTransactionTypes(EloquentBuilder $query, array $types): void

View File

@@ -306,6 +306,8 @@ class BillRepository implements BillRepositoryInterface
{ {
// app('log')->debug('Now in getPaidDatesInRange()'); // app('log')->debug('Now in getPaidDatesInRange()');
Log::debug(sprintf('Search for linked journals between %s and %s', $start->toW3cString(), $end->toW3cString()));
return $bill->transactionJournals() return $bill->transactionJournals()
->before($end)->after($start)->get( ->before($end)->after($start)->get(
[ [

View File

@@ -194,11 +194,19 @@ class BillTransformer extends AbstractTransformer
$searchStart = clone $start; $searchStart = clone $start;
$start->subDay(); $start->subDay();
app('log')->debug(sprintf('Parameters are start: %s end: %s', $start->format('Y-m-d'), $this->parameters->get('end')->format('Y-m-d'))); /** @var Carbon $end */
$end = clone $this->parameters->get('end');
$searchEnd = clone $end;
// move the search dates to the start of the day.
$searchStart->startOfDay();
$searchEnd->endOfDay();
app('log')->debug(sprintf('Parameters are start: %s end: %s', $start->format('Y-m-d'), $end->format('Y-m-d')));
app('log')->debug(sprintf('Search parameters are: start: %s', $searchStart->format('Y-m-d'))); app('log')->debug(sprintf('Search parameters are: start: %s', $searchStart->format('Y-m-d')));
// Get from database when bill was paid. // Get from database when bill was paid.
$set = $this->repository->getPaidDatesInRange($bill, $searchStart, $this->parameters->get('end')); $set = $this->repository->getPaidDatesInRange($bill, $searchStart, $searchEnd);
app('log')->debug(sprintf('Count %d entries in getPaidDatesInRange()', $set->count())); app('log')->debug(sprintf('Count %d entries in getPaidDatesInRange()', $set->count()));
// Grab from array the most recent payment. If none exist, fall back to the start date and pretend *that* was the last paid date. // Grab from array the most recent payment. If none exist, fall back to the start date and pretend *that* was the last paid date.