F
Filament16mo ago
Yuut4

Table Action Not Working

Table action not working properly
3 Replies
Yuut4
Yuut4OP16mo ago
my table actions are not working this is the code i am using
protected function getTableQuery(): Builder
{
$partnerId = $this->ownerRecord->id;


$CURRENT_DATE = Carbon::today()->format('Y-m-d');

$query = PlanPartnerPayment::withTrashed()
->selectRaw('CC.*, @cumulative_balance:=@cumulative_balance + CC.credit-CC.debit AS balance')
->fromRaw('(
SELECT -1 as id, -1 as plan_partner_id, -1 as plan_id, partner_id, DATE_SUB(\'' . $CURRENT_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(\'' . $CURRENT_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_SUB(\'' . $CURRENT_DATE . '\', INTERVAL 1 YEAR)
) CC
JOIN (SELECT @cumulative_balance:=0) r
')->orderBy('CC.date');

return $query;
}
protected function getTableQuery(): Builder
{
$partnerId = $this->ownerRecord->id;


$CURRENT_DATE = Carbon::today()->format('Y-m-d');

$query = PlanPartnerPayment::withTrashed()
->selectRaw('CC.*, @cumulative_balance:=@cumulative_balance + CC.credit-CC.debit AS balance')
->fromRaw('(
SELECT -1 as id, -1 as plan_partner_id, -1 as plan_id, partner_id, DATE_SUB(\'' . $CURRENT_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(\'' . $CURRENT_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_SUB(\'' . $CURRENT_DATE . '\', INTERVAL 1 YEAR)
) CC
JOIN (SELECT @cumulative_balance:=0) r
')->orderBy('CC.date');

return $query;
}
Tables\Actions\EditAction::make('payment')
->label(__('Payment'))
->successNotification(null)
->closeModalByClickingAway(false)
->recordTitle('Payment')
Tables\Actions\EditAction::make('payment')
->label(__('Payment'))
->successNotification(null)
->closeModalByClickingAway(false)
->recordTitle('Payment')
error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'plan_partner_payments.id' in 'where clause' (Connection: mysql, SQL: select CC.*, @cumulative_balance:=@cumulative_balance + CC.credit-CC.debit AS balance from ( SELECT -1 as id, -1 as plan_partner_id, -1 as plan_id, partner_id, DATE_SUB('2023-08-08', 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 = 3 AND date < DATE_SUB('2023-08-08', INTERVAL 1 YEAR) UNION ALL SELECT id, plan_partner_id, plan_id, partner_id, date, debit, credit FROM plan_partner_payments WHERE partner_id = 3 AND date >= DATE_SUB('2023-08- 08', INTERVAL 1 YEAR) ) CC JOIN (SELECT @cumulative_balance:=0) r where plan_partner_payments.id = 54 order by CC.date asc limit 1)
Yuut4
Yuut4OP16mo ago
Flare
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'plan_partner_payments.id' in 'where clause' (Connection: mysql, SQL: select CC.*, @cumulative_balance:=@cumulative_balance + CC.credit-CC.debit AS balance from ( SELECT -1 as id, -1 as plan_partner_id, -1 as plan_id, partner_id, DATE_SUB('2023-08-08', INTERVAL 1 YEAR) as date, ...
Yuut4
Yuut4OP16mo ago
this solves the problem
protected function getTableQuery(): Builder
{
$partnerId = $this->ownerRecord->id;


$CURRENT_DATE = Carbon::today()->format('Y-m-d');

$query = PlanPartnerPayment::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(\'' . $CURRENT_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(\'' . $CURRENT_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_SUB(\'' . $CURRENT_DATE . '\', INTERVAL 1 YEAR)
) plan_partner_payments
JOIN (SELECT @cumulative_balance:=0) r
')->orderBy('plan_partner_payments.date');

return $query;
}
protected function getTableQuery(): Builder
{
$partnerId = $this->ownerRecord->id;


$CURRENT_DATE = Carbon::today()->format('Y-m-d');

$query = PlanPartnerPayment::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(\'' . $CURRENT_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(\'' . $CURRENT_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_SUB(\'' . $CURRENT_DATE . '\', INTERVAL 1 YEAR)
) plan_partner_payments
JOIN (SELECT @cumulative_balance:=0) r
')->orderBy('plan_partner_payments.date');

return $query;
}
Want results from more Discord servers?
Add your server