I have maybe 30 custom fields in my Quote Template. But when I want to transform my quotes into Invoices - how do I transfer the data from the Quote’s custom fields with it? I can’t figure it out.
Please Help.
I have maybe 30 custom fields in my Quote Template. But when I want to transform my quotes into Invoices - how do I transfer the data from the Quote’s custom fields with it? I can’t figure it out.
Please Help.
Custom fields are not copied because the application is not prepared yet to determine which fields could be copied. Maybe we can implement this in the future.
Hi aboutwd,
I replied to another question a few days ago that was about the “copy” feature (Copy custom field values when copying Invoice), then I just found your question today.
This is a question I have found a quick (and dirty) solution for. Here is what I have (in “/application/modules/quotes/controllers/ajax.php”, right after the $quote_tax_rates
section), and it works a treat:
$this->load->model('custom_fields/mdl_custom_fields');
$this->load->model('custom_fields/mdl_quote_custom');
$this->load->model('custom_fields/mdl_invoice_custom');
$quote_customs = $this->mdl_quote_custom->where('quote_id', $this->input->post('quote_id'))->get();
if ($quote_customs->num_rows()) {
$quote_customs = $quote_customs->row();
unset($quote_customs->quote_id, $quote_customs->quote_custom_id);
foreach ($quote_customs as $key => $val) {
$db_array = array(
str_replace('quote', 'invoice', $key) => $val
);
$this->mdl_invoice_custom->save_custom($invoice_id, $db_array);
}
}
This is “dirty” in the sense that there is no checking at all: your quote custom fields must also exist for invoices otherwise this will just not work at all (need a perfect custom field mapping between quotes and invoices), which implies that you have to manually create those for invoices too.
As Kovah said, to have this totally OK, a checking would be the least to do ("does this custom field from “quotes” has an exact equivalent custom field in “invoices” before trying to copy it), and the overall process would ideally become a “full module” feature (which is a lot of work) to be really good (allowing to select what custom fields to copy or not, enabling/disabling custom field creation prior to copy if not existing in invoices, etc.)
But I hope that this piece of code will help.
Cheers!
I am searching exactly for this feature. Unfortunately I cannot get the above code to work. In the ajax.php of version 1.4.7 there is no $quote_tax_rates. So I do not know where to copy this code.
I would be gratefull for any help.
Thanks.
Hi the_ham,
I’ve just checked my own file, and diff-ed it with v1.4.7 (my current version is 1.4.6).
First, please be sure to be using the file “/application/modules/quotes/controllers/ajax.php”.
You will find a method at line 292: public function quote_to_invoice()
. Within that method, you will see this at line 340:
$quote_tax_rates = $this->mdl_quote_tax_rates->where('quote_id', $this->input->post('quote_id'))->get()->result();
=> this is the beginning of the $quote_tax_rates
section I was speaking of.
So, if you want to try this “snippet”, copy-paste it right after the foreach
block that follows the above line, just before the
$response = array(
'success' => 1,
'invoice_id' => $invoice_id
);
And it should work fine.
Cheers,
Jimshell
Hi jimshell,
thanks for your answer. I have stoped this project (and now started it again). It works now, thanks to your help.
Hello,
Apologies for crashing into the topic, I tried your code and I can’t get it to work after numerous attempts and following the instruction you provided. I’m currently using v1.5.5. I have attached the screenshot for the custom fields, is it correct?
Thank You!
Hello ipart,
Your mapping seems perfect, I can’t tell why it is not working…
This “hack” was written for v.1.4.6, so there must have been some changes as you are using v1.5.5?
Do you get any error in logs or something?
I will try to have a look but I can’t promise i will find the solution…
Maybe the new team behind InvoicePlane can help on this? (I hope so)
I have checked the error logs in apache but no errors is logged.
Yeah sure, Thank You!
Any ideas yet?
Hello,
Sorry for replying late: i did check my code and everything seems OK… Maybe the current version of InvoicePlane introduced some changes that prevent it from working?
As you have no errors (or silent ones), you would maybe need to try to check the variables.
For instance, with the below code that you can place where needed throughout the snippet: I’m not familiar with debugging CodeIgniter apps, so this is a quick and dirty debug that outputs content to a file (chose a destination that you can easily reach of course) in order to check step by step where the above code does not work for you… This is needed because we’re in ajax.php and we don’t want to mess up with the response (though we could try to “hack” it to console.log()
in the browse, but that would be even worse ^^)
ob_start();
var_dump($quote_customs); // try and dump the different variables to check if they contain what they should
$result = ob_get_clean();
file_put_contents('somewhere/file-that-you-can-easily-reach.txt', $result);
Try to dump all the variables, step by step, so that you can see where and when something goes wrong…
Sorry for not being of much help on this one…
Cheers,
Jim