Undefined array key "sale_id"

I am using openemr version 7.0.0 (2). When I “Save and Dispense” the drug. It shows the below error.

Warning : Undefined array key “sale_id” in C:\xampp\htdocs\OpenEMR\interface\drugs\dispense_drug.php on line 43
Internal error: the referenced encounter no longer exists. 1 0

I request please guide me why it is showing this error. It is also not getting less the drug inventory.

I think sale_id is generated as <mrn>.<encounter>. So looks like you are trying to sell drug/product to patient #1 for whom there has not been any encounter created.

Or may be a bug if you can replicate it in demo systems.

Thanks for your response.
Now I enable Debugging Options for “All”. Now it is not showing the error which I shared before.
But now it is showing error “Internal error: the referenced encounter no longer exists. 2 0”.

Anyone please suggest what could be the reason. It is also not getting less the inventory. Means not hitting the sale.

Regards,

Are you able to follow same steps in any of the demo systems?

Thanks to Almighty Allah.
My issue has been resolved. Actually I followed the solution of "Kofi Appiah

Below is the solution which I followed.

locate dispense_drug.php below

/openemr/interface/drugs/dispense_drug.php

On line 48, include below line of code

$encounter = $_SESSION[“encounter”];

On line 81, change 0 to $encounter, see below.

from

$sale_id = sellDrug($drug_id, $quantity, $fee, $pid, 0, $prescription_id, $today, $user);

to

$sale_id = sellDrug($drug_id, $quantity, $fee, $pid, $encounter, $prescription_id, $today, $user);

Save and retry.

The error,

Internal error: the referenced encounter no longer exists. 1 0

1 is the PID, whereas 0 is the encounter which has been initialized to 0. However, there’s no encounter ID of 0 in the database. So what you need to do is to get the current encounter and dispense the drug accordingly.

Regards,

You will help future users/developers if you submit this as an issue and associate that with a PR.

i tried this but the error is still there. tried on local wamp and live server.