Automatically use the quote number as reference in the invoice

status:resolved
Tags: #<Tag:0x00007ff4accf2760>

#1

Hi,

I noticed, that when converting a quote to an invoice, there is no database field, which references, the quote number in the invoice.
In my invoices I use to also mention the quote.

It would be easy to add a field to the invoice model ip_invoice.quote_ref and insert the quote name in this field during conversion in

What do you think?
Kind regards
Cornelius


#2

There is no reference in the invoice table but in the quote table:
ip_quotes.invoice_id


#3

OK, how can I use this to print the quote number in the invoice template?


#4

I’m not sure if the data of the quote is already available right now but it would be the best to add this in the backend if not.


#5

Honestly I do not understand you.
When printing the invoice, there is no $quote object available.

So I guess to have the quote_number automatically for printing in the invoice we need to enhance the code - unless there is a functionality I am not aware of, yet.

Addming a field in the pi_invoice table with the originial quote number, which is automatically filled in quote_to_invoicelooks like the best choice to me.

THanks!
(Of course I could issue the pull request :wink:


#6

No, there is no $quote object available but some additional, linked data is available directly in the invoice object.
The only thing missing is the join statement in the backend which queries the quotes for one that has the invoice number saved.

$this->db->join('ip_quotes', 'ip_quotes.invoice_id = ip_invoices.invoice_id', 'left');

https://github.com/InvoicePlane/InvoicePlane/blob/master/application/modules/invoices/models/mdl_invoices.php#L99


#7

Thanks for the hint.
But obviously things are not that simple.

I changed the default_join in mdl_invoices.php like this:

public function default_join()
{
    $this->db->join('ip_clients', 'ip_clients.client_id = ip_invoices.client_id');
    $this->db->join('ip_users', 'ip_users.user_id = ip_invoices.user_id');
    $this->db->join('ip_invoice_amounts', 'ip_invoice_amounts.invoice_id = ip_invoices.invoice_id', 'left');
    $this->db->join('ip_client_custom', 'ip_client_custom.client_id = ip_clients.client_id', 'left');
    $this->db->join('ip_user_custom', 'ip_user_custom.user_id = ip_users.user_id', 'left');
    $this->db->join('ip_invoice_custom', 'ip_invoice_custom.invoice_id = ip_invoices.invoice_id', 'left');
    $this->db->join('ip_quotes', 'ip_quotes.invoice_id = ip_invoices.invoice_id', 'left');
}

(see last line)

But still the invoice object

<pre><?php print_r($invoice); ?></pre>

in the invoice template does not contain quote information.


#8

Eureka!

After adding the table ip_quotes to the select statement all quote information are available in the template.

public function default_select()
{
    $this->db->select("
        SQL_CALC_FOUND_ROWS ip_invoice_custom.*,
        ip_client_custom.*,
        ip_user_custom.*,
        ip_quotes.*,
        ip_users.user_name,
		ip_users.user_company,
		ip_users.user_address_1,
		ip_users.user_address_2,
		ip_users.user_city,

OK, we only need to add these two lines…

Maybe also ip_quotes_custom.


#9

Solved in a commit in branch 1.4.11


closed #10