Topic: Unable to void a Sales Invoice

I'm not sure if this is a bug or not. I've been a very happy use for some years now. Currently using version 2.4.8. Browser is Chromium under Ubuntu and have seen the same behaviour on Firefox on the same machine.

When I go to void a Sales Invoice, I can select the invoice, enter a memo and click Void all as normal. The 'Are you sure ...' page comes up as normal but clicking the Proceed button doesn't work. I briefly see the progress icon spinning but it never leaves the page and never voids the invoice.

Any tips would be greatly appreciated!

Re: Unable to void a Sales Invoice

Looks like the timeout happens. We don't know howmuch records you have and server space given to work.

Probably Php time and our js time out also trouble you. Checkout the other forum  which fixed the timeout issue.
https://frontaccounting.com/punbb/viewtopic.php?pid=39832#p39832

Subscription service based on FA
HRM CRM POS batch Themes

Re: Unable to void a Sales Invoice

kvvaradha wrote:

Looks like the timeout happens. We don't know howmuch records you have and server space given to work.

Probably Php time and our js time out also trouble you. Checkout the other forum  which fixed the timeout issue.
https://frontaccounting.com/punbb/viewtopic.php?pid=39832#p39832

Thanks for the reply. It's definitely not hitting a 10s timeout. The spinning icon appears for less than a second.

Re: Unable to void a Sales Invoice

So it looks something wrong in php  code or in the database columns.
So enable debugging mode to check this issue.

And also check in error log. And if you find error information bring it to us.

Subscription service based on FA
HRM CRM POS batch Themes

Re: Unable to void a Sales Invoice

@Joe, 

Can we set a checkbox for the debugging mode. Basically some of the users are not technically strong to check it. So if we put a checkbox in the default company like the company creation page permission  and allow them to set it from here will be more easier for them to turn it on and get the error informations on their first post itself.

Subscription service based on FA
HRM CRM POS batch Themes

Re: Unable to void a Sales Invoice

Looks like I've got a fiscal year problem.

[13-Aug-2021 15:06:47 Europe/Berlin] <b>DATABASE ERROR :</b> Cannot update audit gl_seq<br>error code : 1048<br>error message : Column 'fiscal_year' cannot be null<br>sql that failed was : UPDATE 2_audit_trail audit LEFT JOIN 2_fiscal_year year ON year.begin<='2021-08-13' AND year.end>='2021-08-13'

The invoices to be voided are in the last fiscal year that ended 2021-06-30. I have not yet created a new fiscal year.

Re: Unable to void a Sales Invoice

If I create a new fiscal year (which we're now in), the problem goes away.

Thanks very much for your help and continuing to maintain such a brilliant piece of software.

Re: Unable to void a Sales Invoice

Ok good to hear that you fixed the problem  and thank you for writing the reason  which will help future users to fix the problem if they face similar one.

Subscription service based on FA
HRM CRM POS batch Themes

Re: Unable to void a Sales Invoice

The code fix:

--- a/core/sales/includes/db/sales_invoice_db.inc
+++ b/core/sales/includes/db/sales_invoice_db.inc
@@ -249,8 +249,9 @@ function void_sales_invoice($type, $type_no)
                if ($deliveries !== 0) {
                        if ($type == ST_SALESINVOICE && count($deliveries) == 1 && get_reference(ST_CUSTDELIVERY, $deliveries[0]) == "auto")
                        {
+                $trans = get_customer_trans($deliveries[0], ST_CUSTDELIVERY);
                                void_sales_delivery(ST_CUSTDELIVERY, $deliveries[0], false);
-                               $date_ = Today();
+                               $date_ = sql2date($trans['tran_date']);
                                add_audit_trail(ST_CUSTDELIVERY, $deliveries[0], $date_, _("Voided."));
                                add_voided_entry(ST_CUSTDELIVERY, $deliveries[0], $date_, "");
                        }
diff --git a/core/sales/includes/db/sales_order_db.inc b/core/sales/includes/db/sales_order_db.inc
index 17952e3..4b4734d 100644
--- a/core/sales/includes/db/sales_order_db.inc
+++ b/core/sales/includes/db/sales_order_db.inc
@@ -89,6 +89,8 @@ function delete_sales_order($order_no, $trans_type)
        begin_transaction();
        hook_db_prevoid($trans_type, $order_no);
 
+    $order = get_sales_order_header($order_no, $trans_type);
+
        $sql = "DELETE FROM ".TB_PREF."sales_orders WHERE order_no=" . db_escape($order_no) 
                . " AND trans_type=".db_escape($trans_type);
 
@@ -98,7 +100,7 @@ function delete_sales_order($order_no, $trans_type)
                .db_escape($order_no) . " AND trans_type=".db_escape($trans_type);
        db_query($sql, "order Detail Delete");
 
-       add_audit_trail($trans_type, $order_no, Today(), _("Deleted."));
+       add_audit_trail($trans_type, $order_no, sql2date($order['ord_date']), _("Deleted."));
        commit_transaction();

Re: Unable to void a Sales Invoice

@joe: can this get into the core?

Re: Unable to void a Sales Invoice

Fixed according to @Braathwaate and committed to stable repo. Thanks @Braathwaate

Joe