am trying to raise an invoice from a master/detail grind. I have 2 questions.
1. In the details grid we need to find price of the product based on selection of product from productid grid. product dropdown has key value pair which is productid and productname from product table. Now how do we show price in price field whenever product is selected?
2. In the details grid, we calculate amount by price+quantity and we have a footer field total amount which is working fine. Now we need to update the amount field of the master with this total amount. As is norm with any invoice, all rows have qty**price as amount and a total amount at the footer. Now we need to update the amount field in master with this total amount. How do we do that?
Please share screenshot / related grid code explaining your query.
WE need to update price based on selection of the product.
$col = array();
$col[“title”] = “Product”;
$col[“name”] = “productid”;
$col[“dbname”] = “invoicedetails.productid”; // this is required as we need to search in name field, not id
$col[“width”] = “180”;
$col[“align”] = “left”;
$col[“search”] = true;
$col[“editable”] = true;
$col[“edittype”] = “select”; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values(“select productid as k, productname as v from product “);
$col[“editoptions”] = array(“value”=>”:;”.$str);
$col[“editoptions”][“onload”][“sql”] = “select productid as k, productname as v from product WHERE subcategoryid = ‘{subcatid}'”;
$col[“formatter”] = “select”; // display label, not value
$cols[] = $col;
$col = array();
$col[“title”] = “Price”;
$col[“name”] = “price”;
$col[“width”] = “100”;
$col[“editable”] = true;
$col[“editrules”] = array(“required”=>True);
//$col[“hidden”] = true;
$cols[] = $col;
Secondly we need to update the amount field in master grid from running total of footer total.
For your first query, you can review this code:
https://www.gridphp.com/demo/demos/appearance/dropdown-callback.phps
Lines:
62-67
122-129
For your second query, please send your query with screenshot for better understanding. Currently it’s not very clear. Most likely you will need custom JS code to read via jquery and fill in desired field.