Class: ErpInventory::ErpApp::Organizer::InventoryMgt::InventoryEntriesController
- Inherits:
-
ErpApp::Organizer::BaseController
- Object
- ErpApp::Organizer::BaseController
- ErpInventory::ErpApp::Organizer::InventoryMgt::InventoryEntriesController
- Defined in:
- app/controllers/erp_inventory/erp_app/organizer/inventory_mgt/inventory_entries_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #show_summary ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/erp_inventory/erp_app/organizer/inventory_mgt/inventory_entries_controller.rb', line 55 def create begin ActiveRecord::Base.transaction do entry = InventoryEntry.new entry.description=params[:description] entry.sku=params[:sku] entry.unit_of_measurement_id=params[:unit_of_measurement] entry.number_in_stock=params[:number_in_stock] entry.number_available=params[:number_available] entry.product_type_id=params[:product_type_id] entry.save location_assignment = InventoryEntryLocation.new location_assignment.inventory_entry = entry location_assignment.facility_id = params[:inventory_facility] location_assignment.save render :json => {:success => true, :data => entry.to_hash(:only => [:id, :description, :created_at, :updated_at], :model => 'InventoryEntry')} end rescue => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") render :json => {:success => false, :message => ex.} end end |
#destroy ⇒ Object
115 116 117 118 119 120 |
# File 'app/controllers/erp_inventory/erp_app/organizer/inventory_mgt/inventory_entries_controller.rb', line 115 def destroy entry = InventoryEntry.find(params[:inventory_entry_id]) render :json => {:success => entry.destroy} end |
#edit ⇒ Object
82 83 84 |
# File 'app/controllers/erp_inventory/erp_app/organizer/inventory_mgt/inventory_entries_controller.rb', line 82 def edit puts "edit called" end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/erp_inventory/erp_app/organizer/inventory_mgt/inventory_entries_controller.rb', line 7 def index offset = params[:start] || 0 limit = params[:limit] || 25 query_filter = params[:query_filter].blank? ? nil : params[:query_filter].strip facility_id = params[:facility_id].blank? ? nil : params[:facility_id].strip party_id = params[:party_id] inventory_entry_tbl = InventoryEntry.arel_table # scope by party if have party id if party_id.blank? statement = InventoryEntry.order('created_at asc') else statement = InventoryEntry.joins(product_type: :product_type_pty_roles).where('product_type_pty_roles.party_id = ?', party_id).order('created_at asc') end # apply filters if present statement = statement.where(inventory_entry_tbl[:description].matches(query_filter + '%')) if query_filter # apply facility if present statement = statement.joins(:inventory_entry_locations).where('facility_id = ?', facility_id) if facility_id # Get total count of records total = statement.count # Apply limit and offset inventory_entries = statement.offset(offset).limit(limit) render :json => {:success => true, :total => total, :inventory_entries => inventory_entries.collect { |entry| entry.to_data_hash }} end |
#new ⇒ Object
52 53 |
# File 'app/controllers/erp_inventory/erp_app/organizer/inventory_mgt/inventory_entries_controller.rb', line 52 def new end |
#show ⇒ Object
45 46 47 48 49 50 |
# File 'app/controllers/erp_inventory/erp_app/organizer/inventory_mgt/inventory_entries_controller.rb', line 45 def show entry = InventoryEntry.find(params[:inventory_entry_id]) render :json => {:success => true, :data => entry.to_data_hash} end |
#show_summary ⇒ Object
39 40 41 42 43 |
# File 'app/controllers/erp_inventory/erp_app/organizer/inventory_mgt/inventory_entries_controller.rb', line 39 def show_summary @inventory_entry = InventoryEntry.find(params[:id]) rescue nil end |
#update ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/erp_inventory/erp_app/organizer/inventory_mgt/inventory_entries_controller.rb', line 86 def update begin ActiveRecord::Base.transaction do entry = InventoryEntry.find(params[:inventory_entry_id]) current_facility = entry.current_storage_facility entry.description=params[:description] entry.sku=params[:sku] entry.unit_of_measurement_id=params[:unit_of_measurement] entry.number_available=params[:number_available] entry.number_in_stock=params[:number_in_stock] entry.product_type_id=params[:product_type_id] entry.save if current_facility.id != params[:inventory_facility].to_i location_assignment = InventoryEntryLocation.new location_assignment.inventory_entry = entry location_assignment.facility_id = params[:inventory_facility] location_assignment.save end render :json => {:success => true, :data => entry.to_hash(:only => [:id, :description, :created_at, :updated_at], :model => 'InventoryEntry')} end rescue Exception => e Rails.logger.error e. Rails.logger.error e.backtrace.join("\n") render :json => {:success => false, :message => e.} end end |