Firstly, thank you Alastair for the module. This is not a new post but for some reason I was unable to reply to the post above. I may have downloaded the module from the wrong place, but on a payments-basis GST return, the input tax on a paid supplier invoice was added to the output tax instead of being deducted from it.

For example, output GST of 4,434.79 and input GST of 375.52 was reported as a net payable of 4,810.31. The correct net payable is 4,059.27.

FrontAccounting stores a supplier payment with a negative ov_amount. The input-tax part of the report joined supp_trans on the payment (trans_type_from) and divided by that payment total. Dividing by a negative amount flipped the sign of the input GST, so collectible + payable added the input tax instead of subtracting it.

The fix is to divide by the supplier invoice total (trans_type_to). The invoice amount is positive, the existing -1 then makes the input GST a deduction, and the net payable is correct.

File: includes/tax_cash_db.inc

In tax_cash_sql(), change the supplier-allocation block from:

ttd.net_amount*sa.amt/round(ov_amount+ov_gst+ov_discount,6)*ex_rate net_input,
-1*ttd.amount*sa.amt/round(ov_amount+ov_gst+ov_discount,6)*ex_rate collectible,
...
INNER JOIN ".TB_PREF."supp_trans st
    ON st.type = sa.trans_type_from
    AND st.trans_no = sa.trans_no_from

to:

ttd.net_amount*sa.amt/round(inv.ov_amount+inv.ov_gst+inv.ov_discount,6)*ex_rate net_input,
-1*ttd.amount*sa.amt/round(inv.ov_amount+inv.ov_gst+inv.ov_discount,6)*ex_rate collectible,
...
INNER JOIN ".TB_PREF."supp_trans inv
    ON inv.type = sa.trans_type_to
    AND inv.trans_no = sa.trans_no_to

After the change, the input line shows as a negative amount and the total payable is the output GST less the input GST. The same figure is used by the Tax Details (Cash Basis) report.

FrontAccounting 2.4.20 on PHP 8.3, site published through Cloudflare with the proxy on (orange cloud).

Problem:
The login was dropped every few screens, and in particular each time a main-menu tab was opened (index.php?application=...). Logging in again worked, until the next tab.

SessionManager stores the client address on the session and, in preventHijacking(), treats a different address as a hijack and wipes the session. Behind Cloudflare, REMOTE_ADDR is a Cloudflare edge address, and that address changes from one request to the next. The visitor has not changed. The next menu click looks like a hijack, and the login is cleared.

Solution:
I enabled a solution that works for all users as it currently does, but also for servers who use Cloudflare Orange.

What I changed:
1. The address stored and compared is the visitor address Cloudflare sends (CF-Connecting-IP), and only when the request also has Cloudflare's CF-RAY header. Both headers are required so a client who simply sends CF-Connecting-IP is not trusted.
Users who are not coming through Cloudflare orange-cloud, or through another proxy that sets those two headers, are not affected. A LAN client, or a WAN client hitting the server directly, has no CF-RAY header, so clientAddress() returns REMOTE_ADDR and the check is the same as before.

2. I removed the 5% random call to regenerateSession() on every request. That path is not specific to Cloudflare. On PHP 8, regenerateSession() (session_regenerate_id, session_write_close, then session_start again) drops the logged-in session on the requests where it runs. A real address mismatch still calls regenerateSession().

Code:
------
Replaced, in sessionStart():
$_SESSION['IPaddress'] = $_SERVER['REMOTE_ADDR'];

with:
$_SESSION['IPaddress'] = $this->clientAddress();

------

Removed, immediately after regenerateSession() in that same block:
// Give a 5% chance of the session id changing on any request
}
elseif (rand(1, 100) <= 5)
{
    $this->regenerateSession();
}

------

Replaced, in preventHijacking():
if ($_SESSION['IPaddress'] != $_SERVER['REMOTE_ADDR'])
    return false;

with:

if ($_SESSION['IPaddress'] != $this->clientAddress())
    return false;

------

Added, immediately above preventHijacking():
// Visitor address. Cloudflare's own address changes between requests, so the
// session is kept against CF-Connecting-IP when that request came through Cloudflare.
function clientAddress()
{
    if (!empty($_SERVER['HTTP_CF_CONNECTING_IP']) && !empty($_SERVER['HTTP_CF_RAY']))
        return $_SERVER['HTTP_CF_CONNECTING_IP'];
    return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
}

------
After this, one fresh login stays put across the menu tabs. I'm happy for this to be adjusted if there is a preferred way to handle it in the next release.