Sort a nasty bug in budget limit collection #508

This commit is contained in:
James Cole 2016-12-30 09:02:48 +01:00
parent 7a57670925
commit d146476c91
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -202,29 +202,32 @@ class BudgetRepository implements BudgetRepositoryInterface
->with(['budget']) ->with(['budget'])
->where('budgets.user_id', $this->user->id) ->where('budgets.user_id', $this->user->id)
->where( ->where(
function (Builder $q1) use ($start, $end) { function (Builder $q5) use ($start, $end) {
$q1->where( $q5->where(
function (Builder $q2) use ($start, $end) { function (Builder $q1) use ($start, $end) {
$q2->where('budget_limits.end_date', '>=', $start->format('Y-m-d 00:00:00')); $q1->where(
$q2->where('budget_limits.end_date', '<=', $end->format('Y-m-d 00:00:00')); function (Builder $q2) use ($start, $end) {
$q2->where('budget_limits.end_date', '>=', $start->format('Y-m-d 00:00:00'));
$q2->where('budget_limits.end_date', '<=', $end->format('Y-m-d 00:00:00'));
}
)
->orWhere(
function (Builder $q3) use ($start, $end) {
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d 00:00:00'));
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d 00:00:00'));
}
);
} }
) )
->orWhere( ->orWhere(
function (Builder $q3) use ($start, $end) { function (Builder $q4) use ($start, $end) {
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d 00:00:00')); // or start is before start AND end is after end.
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d 00:00:00')); $q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d 00:00:00'));
$q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d 00:00:00'));
} }
); );
} }
) )->get(['budget_limits.*']);
->orWhere(
function (Builder $q4) use ($start, $end) {
// or start is before start AND end is after end.
$q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d 00:00:00'));
$q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d 00:00:00'));
}
)
->get(['budget_limits.*']);
return $set; return $set;
} }
@ -261,31 +264,34 @@ class BudgetRepository implements BudgetRepositoryInterface
{ {
$set = $budget->budgetLimits() $set = $budget->budgetLimits()
->where( ->where(
function (Builder $q1) use ($start, $end) { function (Builder $q5) use ($start, $end) {
// budget limit ends within period $q5->where(
$q1->where( function (Builder $q1) use ($start, $end) {
function (Builder $q2) use ($start, $end) { // budget limit ends within period
$q2->where('budget_limits.end_date', '>=', $start->format('Y-m-d 00:00:00')); $q1->where(
$q2->where('budget_limits.end_date', '<=', $end->format('Y-m-d 00:00:00')); function (Builder $q2) use ($start, $end) {
$q2->where('budget_limits.end_date', '>=', $start->format('Y-m-d 00:00:00'));
$q2->where('budget_limits.end_date', '<=', $end->format('Y-m-d 00:00:00'));
}
)
// budget limit start within period
->orWhere(
function (Builder $q3) use ($start, $end) {
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d 00:00:00'));
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d 00:00:00'));
}
);
} }
) )
// budget limit start within period
->orWhere( ->orWhere(
function (Builder $q3) use ($start, $end) { function (Builder $q4) use ($start, $end) {
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d 00:00:00')); // or start is before start AND end is after end.
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d 00:00:00')); $q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d 00:00:00'));
} $q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d 00:00:00'));
); }
);
} }
) )->get(['budget_limits.*']);
->orWhere(
function (Builder $q4) use ($start, $end) {
// or start is before start AND end is after end.
$q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d 00:00:00'));
$q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d 00:00:00'));
}
)
->get();
return $set; return $set;
} }