change query and some func: in inv:
This commit is contained in:
@@ -4,7 +4,7 @@ class Inventory::InventoryController < BaseInventoryController
|
||||
least_stock = "SELECT (CASE WHEN SIGN(MIN(stock_journals.balance)) > 0
|
||||
THEN MIN(stock_journals.balance) WHEN stock_journals.remark NOT LIKE '%out of stock%'
|
||||
THEN (SELECT balance FROM stock_journals
|
||||
WHERE item_code = inventory_definitions.item_code AND balance > 0
|
||||
WHERE item_code = inventory_definitions.item_code
|
||||
AND remark NOT LIKE '%out of stock%'
|
||||
ORDER BY created_at DESC LIMIT 1) ELSE 0 END)
|
||||
FROM stock_journals
|
||||
|
||||
@@ -45,11 +45,19 @@ class InventoryDefinition < ApplicationRecord
|
||||
|
||||
def self.modify_balance(item, stock, inventory_definition) #saleitemObj
|
||||
if stock.balance.to_i >= item.qty
|
||||
puts ">> stock is greater than orde qty"
|
||||
puts ">> stock is greater than order qty"
|
||||
StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition)
|
||||
else
|
||||
puts " << stock is less than order qty"
|
||||
StockJournal.add_to_journal(item, stock.balance, "out of stock", inventory_definition)
|
||||
item_data = item
|
||||
if stock.balance.to_i > 0
|
||||
item_data.qty = item.qty.to_i - stock.balance.to_i
|
||||
StockJournal.add_to_journal(item_data, stock.balance, "out of stock", inventory_definition)
|
||||
item.qty = stock.balance.to_i
|
||||
StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition)
|
||||
else
|
||||
StockJournal.add_to_journal(item_data, stock.balance, "out of stock", inventory_definition)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user