F
Filament16mo ago
Yuut4

Custom form filter is not applying

the filter is not applying
3 Replies
Yuut4
Yuut4OP16mo ago
I'm doing a custom filter, but it's not applying the same this is my code
Yuut4
Yuut4OP16mo ago
Yuut4
Yuut4OP16mo ago
this is my current filter and it still doesn't apply,
->query(function (Builder $query, array $data, $livewire): Builder {
$partnerId = $livewire->ownerRecord->id;
$date = $data['date'];
if (isset($date)) {
$date = explode(' ', $date);
$date = $date[0];
///*dd(*/return $query->where('date', $date)->where('partner_id', $partnerId)->withTrashed()/*->get())*/;
$query = $query->withTrashed()->selectRaw('plan_partner_payments.*, @cumulative_balance:=@cumulative_balance + plan_partner_payments.credit-plan_partner_payments.debit AS balance')
->fromRaw('(
SELECT -1 as id, -1 as plan_partner_id, -1 as plan_id, partner_id, DATE_SUB(\'' . $date . '\', INTERVAL 1 YEAR) as date,
CASE WHEN SUM(credit)-SUM(debit) < 0 THEN SUM(credit)-SUM(debit) ELSE 0 END as debit,
CASE WHEN SUM(credit)-SUM(debit) >= 0 THEN SUM(credit)-SUM(debit) ELSE 0 END as credit
FROM plan_partner_payments
WHERE partner_id = ' . $partnerId . ' AND date < DATE_SUB(\'' . $date . '\', INTERVAL 1 YEAR)
UNION ALL
SELECT id, plan_partner_id, plan_id, partner_id, date, debit, credit
FROM plan_partner_payments
WHERE partner_id = ' . $partnerId . ' AND date = \'' . $date . '\'
) plan_partner_payments
JOIN (SELECT @cumulative_balance:=0) r');
}
return $query;
}),
->query(function (Builder $query, array $data, $livewire): Builder {
$partnerId = $livewire->ownerRecord->id;
$date = $data['date'];
if (isset($date)) {
$date = explode(' ', $date);
$date = $date[0];
///*dd(*/return $query->where('date', $date)->where('partner_id', $partnerId)->withTrashed()/*->get())*/;
$query = $query->withTrashed()->selectRaw('plan_partner_payments.*, @cumulative_balance:=@cumulative_balance + plan_partner_payments.credit-plan_partner_payments.debit AS balance')
->fromRaw('(
SELECT -1 as id, -1 as plan_partner_id, -1 as plan_id, partner_id, DATE_SUB(\'' . $date . '\', INTERVAL 1 YEAR) as date,
CASE WHEN SUM(credit)-SUM(debit) < 0 THEN SUM(credit)-SUM(debit) ELSE 0 END as debit,
CASE WHEN SUM(credit)-SUM(debit) >= 0 THEN SUM(credit)-SUM(debit) ELSE 0 END as credit
FROM plan_partner_payments
WHERE partner_id = ' . $partnerId . ' AND date < DATE_SUB(\'' . $date . '\', INTERVAL 1 YEAR)
UNION ALL
SELECT id, plan_partner_id, plan_id, partner_id, date, debit, credit
FROM plan_partner_payments
WHERE partner_id = ' . $partnerId . ' AND date = \'' . $date . '\'
) plan_partner_payments
JOIN (SELECT @cumulative_balance:=0) r');
}
return $query;
}),
does anyone know what could be happening? Is it because it doesn't work if you don't have where?
Want results from more Discord servers?
Add your server