cols='`tabItem`.name AS "Item Code", `tabItem`.item_name AS "Item Name", `tabItem`.description AS "Description", `tabItem`.stock_uom AS "Stock UOM"';
cond='(IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND `tabItem`.is_stock_item = "Yes"';
if(item_code)cond+=repl(' AND `tabItem`.name = %(item)s',{item:'"'+item_code+'"'});
cond+=' AND `tabStock Ledger Entry`.item_code = `tabItem`.name'
cols='`tabItem`.name AS "Item Code", `tabItem`.item_name AS "Item Name", `tabItem`.description AS "Description", `tabItem`.stock_uom AS "Stock UOM", `tabWarehouse`.name AS "Warehouse", `tabWarehouse`.warehouse_type AS "Warehouse Type"';
cond='(IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND `tabItem`.is_stock_item = "Yes" AND `tabWarehouse`.docstatus < 2';
if(item_code)cond+=repl(" AND `tabItem`.name = %(item)s",{item:"'"+item_code+"'"});
if(warehouse)cond+=repl(" AND `tabWarehouse`.name = %(warehouse)s",{warehouse:"'"+warehouse+"'"});
cond+=repl(' AND `tabStock Ledger Entry`.item_code = `tabItem`.name AND `tabStock Ledger Entry`.warehouse = `tabWarehouse`.name %(ware_type_cond)s',{ware_type_cond:ware_type_cond})
q=repl("SELECT %(cols)s FROM %(tables)s, `tabStock Ledger Entry` WHERE %(cond)s %(date_cond)s GROUP BY %(group_by)s",{cols:cols,tables:tables,cond:cond,date_cond:date_cond,group_by:group_by});