Changing payment dropdown

I have added a custom status so I can mark invoices that won’t ever be paid (unfortunately this is something I have to deal with every once in a while). I would like to remove the invoice from the select field on the payments page (/payments/form). I have found this is the way that InvoicePlane gets the open invoices:

    $open_invoices = $this->mdl_invoices
        ->where('ip_invoice_amounts.invoice_balance >', 0)
        ->or_where('ip_invoice_amounts.invoice_balance <', 0)
        ->get()->result();

This is in “application/models/payments/controllers/Payments.php”, but I how to I add “WHERE ip_invoices.invoice_status_id != 5” to the mix?

Which version are you using.

The later versions have moved payments into the payment module, and moved SQL statements into the model

This is what I see in the payment modules.

$open_invoices = $this->mdl_invoices->is_open()->get()->result();

1 Like

Version 1.5.9… but is this the solution?

    $open_invoices = $this->mdl_invoices
	->where('ip_invoices.invoice_status_id !=', 5)
        ->where('ip_invoice_amounts.invoice_balance >', 0)
        ->or_where('ip_invoice_amounts.invoice_balance <', 0)
        ->get()->result();

Add a new function to the invoices model

application/modules/invoices/models/Mdl_invoices.php

public function is_not_stale()
{
    $this->filter_where('invoice_status_id <> 5');
    return $this;
}

Then in your controller, change

$open_invoices = $this->mdl_invoices->is_open()->get()->result();

to

$open_invoices = $this->mdl_invoices->is_open()->is_not_stale()->get()->result();

1 Like