change query
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
class Inventory::InventoryController < BaseInventoryController
|
class Inventory::InventoryController < BaseInventoryController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
def index
|
def index
|
||||||
least_stock = "SELECT (CASE WHEN SIGN(MIN(stock_journals.balance)) > 0
|
least_stock = "SELECT (CASE WHEN stock_journals.remark != 'out of stock'
|
||||||
THEN MIN(stock_journals.balance)
|
|
||||||
WHEN stock_journals.remark != 'out of stock'
|
|
||||||
THEN (SELECT balance FROM stock_journals
|
THEN (SELECT balance FROM stock_journals
|
||||||
WHERE item_code = inventory_definitions.item_code AND remark != 'out of stock'
|
WHERE item_code = inventory_definitions.item_code AND remark != 'out of stock'
|
||||||
ORDER BY created_at DESC LIMIT 1) ELSE 0 END)
|
ORDER BY created_at DESC LIMIT 1) ELSE 0 END)
|
||||||
@@ -17,7 +15,7 @@ class Inventory::InventoryController < BaseInventoryController
|
|||||||
(#{least_stock}) as balance")
|
(#{least_stock}) as balance")
|
||||||
.joins(" LEFT JOIN stock_journals sj ON sj.inventory_definition_id=inventory_definitions.id")
|
.joins(" LEFT JOIN stock_journals sj ON sj.inventory_definition_id=inventory_definitions.id")
|
||||||
.group("inventory_definitions.item_code")
|
.group("inventory_definitions.item_code")
|
||||||
.order("(CASE WHEN sj.balance > 0 THEN MIN(sj.balance) ELSE NULL END )")
|
.order("balance ASC")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user