forked from ones006/inventory_v2
/
beginning_balances_controller.rb
65 lines (58 loc) · 1.99 KB
/
beginning_balances_controller.rb
1
2
3
4
5
6
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class BeginningBalancesController < ApplicationController
before_filter :authenticate
before_filter :assign_tab
def index
@search = current_company.beginning_balances.search(params[:search])
@beginning_balances = @search.paginate(:page => params[:page])
end
def show
@beginning_balance = BeginningBalance.find(params[:id])
end
def new
@categories = current_company.leaf_categories
@beginning_balance = current_company.beginning_balances.new
@beginning_balance.number = BeginningBalance.suggested_number(current_company)
end
def create
@beginning_balance = current_company.beginning_balances.new(params[:beginning_balance])
@beginning_balance.destination_warehouse = current_company.default_warehouse
if params[:get_mrs] && params[:get_mrs].to_i == 1
@categories = current_company.leaf_categories
@beginning_balance.build_entries_from_categories
@beginning_balance.entries.build
render("new", :layout => false) and return
end
if @beginning_balance.save
flash[:notice] = "Successfully created beginning balance."
redirect_to beginning_balances_url
else
@categories = current_company.leaf_categories
render :action => 'new'
end
end
def edit
@categories = current_company.leaf_categories
@beginning_balance = BeginningBalance.find(params[:id])
end
def update
@beginning_balance = BeginningBalance.find(params[:id])
if @beginning_balance.update_attributes(params[:beginning_balance])
flash[:notice] = "Successfully updated beginning balance."
redirect_to beginning_balances_url
else
@categories = current_company.leaf_categories
render :action => 'edit'
end
end
def destroy
@beginning_balance = BeginningBalance.find(params[:id])
@beginning_balance.delete
flash[:notice] = "Beginning Balance deleted successfully"
redirect_to beginning_balances_url
end
private
def assign_tab
@tab = 'transactions'
@current = 'bb'
end
end