Topic: Print a large number of invoices at once

In Reports and Analysis, I tried to print all invoices in the past one month but i got error

Maximum execution time of 30 seconds exceeded in ..../reporting/includes/html_entity_decode_php4.php on line 98

Which file should i go in to amend the execution time? Or any other better ways to print a large number of invoices at the same time? Thank you.

Re: Print a large number of invoices at once

Edit php.ini in your webserver - increase the value of the variable max_execution_time from 30 (secs) to say 120 or 180 or more depending on the time it takes to prepare your report. You will need to restart your webserver process generally.

Re: Print a large number of invoices at once

Issue solved. Thank you!

Re: Print a large number of invoices at once

You might also want to refer the php.ini max_input_vars setting to increasing it from the default of 1000 to 3000 or beyond as instructed in this thread.

Re: Print a large number of invoices at once

Thank you for your suggestions.

I have one more question -

I have invoices denominated in 2 currencies - USD (base currency) and EUR. How can I print only all EUR denominated invoices in a particular month?

I used the 'Print Invoices' function under the 'Customer' class of 'Customer and Sales Report'
I tried using the Currency Filter but the results will give me both USD and EUR invoices.

The reason I need to print only EUR invoices is because I want to add a comment line only on EUR invoices. Appreciate your help. Thank you.

6 (edited by apmuthu 02/11/2015 05:14:22 pm)

Re: Print a large number of invoices at once

Customer Branches are by default not classified into any group.
Default Sales Groups available are Small, Medium, Large.
Sales => Sales Groups
You can create USD and EUR Sales Groups and appropriately group the customer branches and then print them by appropriate Group filter.
There is no Group filter currently in the Invoice Printing script - rep107.php - you will have to hack that in.

There is a currency filter in the Invoice Printing Form and even if you choose all the invoices / customers, probably this filter may kick in - please provide feedback on it.

Not even one report request form provides for Sales Groups Filter.

@joe: Please provide Sales Group Filter in all appropriate reports.

Re: Print a large number of invoices at once

apmuthu wrote:

There is a currency filter in the Invoice Printing Form and even if you choose all the invoices / customers, probably this filter may kick in - please provide feedback on it.


This filter does not seem to work. Does this 'Currency' correspond to 'Customer's Currency' field under 'Add and Manage Customers' function? What should I change to make this filter kick in? Thank you.

8 (edited by apmuthu 02/11/2015 06:29:45 pm)

Re: Print a large number of invoices at once

Hope you have set the Customer Currency correctly. Otherwise, company's currency will be used and it will not be filterable. Currency is used in the payment link generation in pdf_report.inc in it's End() method. I have not been able to ascertain where else the "currency variable taken from the report request form" is used in report generation.

Re: Print a large number of invoices at once

@joe: The following info will be useful in getting Sales Groups into all pertinent reports:

functions in includes/ui/ui_lists.inc:

sales_groups_list($name, $selected_id=null, $special_option=false)
    used in function sales_groups_list_cells
sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
    used in sales_groups_list_row
sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
    used in sales/manage/customer_branches.php (data entry and updation)
    used in sales/manage/recurrent_invoices.php (selection for recurrent invoice generation)


functions in sales/includes/db/sales_groups_db.inc:

The following 5 functions are used only once in sales/manage/sales_groups.php
add_sales_group($description)
update_sales_group($selected_id, $description)
delete_sales_group($selected_id)
get_sales_groups($show_inactive)
get_sales_group($selected_id)


get_sales_group_name($group_no)
    used in sales/manage/recurrent_invoices.php
    used in sales/create_recurrent_invoices.php

Re: Print a large number of invoices at once

apmuthu wrote:

Hope you have set the Customer Currency correctly. Otherwise, company's currency will be used and it will not be filterable. Currency is used in the payment link generation in pdf_report.inc in it's End() method. I have not been able to ascertain where else the "currency variable taken from the report request form" is used in report generation.

I think I set up the Customer Currency correctly because there is nowhere else I can set currency. I found this code in rep107

$cur = get_company_Pref('curr_default');

It seems the currency filter is not taking the Customer Currency but just the 'Home Currency' under Company Set Up.

What should I do so that the Currency Filter will work as per the Customer Currency?

Thank you.

Re: Print a large number of invoices at once

I just looked deeper into the code in rep107 and it seems that currency is actually not considered in the filters
Those 'if' functions only cover invoices, debtor_no and email (I hope I am reading the code directly...)
Can this be fixed so to include currency filter? Many thanks.


            if (!exists_customer_trans(ST_SALESINVOICE, $i))
                continue;
........
            if($customer && $myrow['debtor_no'] != $customer) {
                continue;
            }
.......

            if ($email == 1)

Re: Print a large number of invoices at once

I wil have a look into this.

Joe

Re: Print a large number of invoices at once

@joe: Whilst incorporating the Currency filter in the appropriate report request forms, plesse try to include Sales Group filter as well. The latter will help manage exceptions easily with the help of temporary groups.

In FA 2.4, we can allow customer branches be part of multiple Sales Groups and possibly include a fallback Sales Group in the Customer record (debtor_master) as well.

Re: Print a large number of invoices at once

The currency filter do not work in rep107.php. This will be fixed for 2.3 later this evening.

The Sales Group filter will require more work elsewhere, so this will have to wait and be included during 2.4.

Joe

Re: Print a large number of invoices at once

The currency filter didn't work for most documents, so these have been fixed and the 2.3 HG repo has been updated.

The fixed Invoice Document kan be downloaded here.

/Joe

16 (edited by apmuthu 02/13/2015 05:55:04 am)

Re: Print a large number of invoices at once

@joe: Thanks. That was fast and elegant.

For the record:
ALL_TEXT, the blank string constant, is defined in include/types.inc and is included in includes/main.inc which in turn is included in includes/session.inc which is included in all report files.
Hence it may be safely used in all reports.

17 (edited by apmuthu 02/13/2015 03:04:09 pm)

Re: Print a large number of invoices at once

All reports affected by the currency filter commit other than rep108.php get their results from other functions. In FA 2.4, we can consider filtering them in the WHERE clause in the source function's SQL tself.

In rep108.php, the sql is executed inline and can hence be filtered in the WHERE clause itself instead of in the php loop after the fact. The patch below achieves it:

--- reporting/rep108.php    Fri Feb 13 20:23:10 2015
+++ reporting/rep108.php    Fri Feb 13 20:19:18 2015
@@ -86,18 +86,17 @@
    if ($orientation == 'L')
         recalculate_cols($cols);
  
-    $sql = "SELECT debtor_no, name AS DebtorName, address, tax_id, curr_code, curdate() AS tran_date FROM ".TB_PREF."debtors_master";
+    $sql = "SELECT debtor_no, name AS DebtorName, address, tax_id, curr_code, curdate() AS tran_date FROM ".TB_PREF."debtors_master WHERE 1 ";
     if ($customer != ALL_TEXT)
-        $sql .= " WHERE debtor_no = ".db_escape($customer);
-    else
+        $sql .= " AND debtor_no = ".db_escape($customer);
+    if ($currency != ALL_TEXT)
+        $sql .= " AND curr_code = ".db_escape($currency);
+
         $sql .= " ORDER by name";
     $result = db_query($sql, "The customers could not be retrieved");
 
     while ($myrow=db_fetch($result))
     {
-        if ($currency != ALL_TEXT && $myrow['curr_code'] != $currency) {
-            continue;
-        }    
         $date = date('Y-m-d');
 
         $myrow['order_'] = "";
Post's attachments

rep108_currency_re-run.zip 5.5 kb, 1 downloads since 2015-02-13 

You don't have the permssions to download the attachments of this post.

Re: Print a large number of invoices at once

Thanks both for your help! I have replaced rep107, 108, 109, 111, 112, 113 in my system and now the currency filter works perfectly! Very helpful. Thank you.

Re: Print a large number of invoices at once

Strange thing happened.

With the new rep107.php file, the function under 'Customer and Sales Reports' --> 'Print Invoices' works well.
However, if I go to 'Sales' --> 'Customer Transaction Inquiry' and then print individual invoice there, I get blank page.

I replaced with the old rep107.php file and then printing in 'Customer Transaction Inquiry' returns normal.

With the new rep113.php file, printing credit note in  'Customer Transaction Inquiry' has no issue.

20 (edited by apmuthu 02/13/2015 06:35:05 pm)

Re: Print a large number of invoices at once

Have you tried to clear all the cache and close all instances of your browser before trying it?

Take a dump of all variables available while entering rep107.php from each menu link instance and report the difference. It may have something to do with the $currency variable not being defined or defined wrongly - under what set of values I cannot ascertain as it works correctly for me.

Re: Print a large number of invoices at once

A new update of the file rep107.php has been done. please make a reload of the file from HG repository.

/Joe

Re: Print a large number of invoices at once

This means that this error pre-existed in FA. In FA v2.4, we must make sure that $customer has some value (even if blank) before arriving at rep107.php since the very same construct "if (!exists_customer_trans(....." precedes the current commit lines of rep107.php in rep110.php and rep113.php and the equivalent "if($myrow['debtor_no'] != $customer) {" instead of the current commit lines will always be sufficient even if not coded so.

@joe: thanks for spotting and correcting it forthwith. I had tested in Windoze that was probably more forgiving of absent variables!