This topic is locked
[SOLVED]

Disable a button in the Details table based on a field in the Master table

10/7/2024 5:44:50 AM
PHPRunner General questions
A
alfonso authorDevClub member

In phprunner 10.91 I have a loan system with a table called inventory (with id called inventory_id) and another table called partners (with id called partner_id). The table that relates them is called loans and has the fields inventory_id and partner_id. It also has two fields to control the date. One is the date_pres field that stores the date on which the loan is made and another field called date_dev that stores the date on which the loan is returned.
What I need is that if the date_dev field is empty, that item cannot be loaned.
The loans table works correctly when adding a loan the inventory item that has the field loaned = 1 does not appear. The problem is when I use spreadsheet mode within the inventory item. Then, the Add new button is always available even if the item is loaned and does not have a return date.
In a BeforeAdd event I can add a code like this:

But it would be much better if we could disable the add button when the master table "inventory" had a 1 in the "borrowed" field. Or at least use a sweet alert

I try disable inlineadd button in ListPage->Before Display`global $conn;

// Consulta para verificar si el artículo ya está prestado
$strSQLExists1 = "SELECT * FROM inventario WHERE id_inventario = '".$values["inventario_id"]."'";
$rsExists1 = db_query($strSQLExists1, $conn);
$data = db_fetch_array($rsExists1);

// Verifica si el registro existe en la tabla inventario
if ($data) {

// Si el artículo ya está prestado (prestado = 1), bloquear el préstamo
if ($data["prestado"] == 1) {

$pageObject->hideItem("inline_add");
}

}
`
But .$values["inventario_id"] seems to be empty

Any idea? Thanks

A
alfonso authorDevClub member 10/7/2024

See image:

img alt

Sergey Kornilov admin 10/7/2024

It is hard to fully understand what you trying to achieve but I can tell you that BeforeDisplay event is not the right place to do so. As you can see in documentation, BeforeDisplay event doesn't provide access to $values array. $values array is usually available in those events that work with a single record while on the List page you have multiple records.

More info:
https://xlinesoft.com/phprunner/docs/before_display.htm

A
alfonso authorDevClub member 10/7/2024

I don't know where to put the code so that if in the Master table called inventory a field called borrowed is equal to 1 then in the loans table it doesn't allow adding records

C
cristi 10/9/2024

If you don't need the add button for details disabled on the fly then you can use php code in the list page before display of the detail table like this using getMasterRecord():

$master= $pageObject->getMasterRecord();
$master_data = $master["borrowed"]; //here you define the variable $master_data with the data from you master table
if ($master_data==1)
{
$pageObject->hideItem("add");
$pageObject->hideItem("inline_add");
}
A
alfonso authorDevClub member 10/12/2024

it works. Thanks