Skip to content

Commit

Permalink
fix beginning balance edit action
Browse files Browse the repository at this point in the history
  • Loading branch information
rbudiharso committed Oct 27, 2010
1 parent 48a1a9d commit 4ca9352
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 9 deletions.
9 changes: 8 additions & 1 deletion app/controllers/beginning_balances_controller.rb
Expand Up @@ -21,7 +21,7 @@ def create
@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(params[:categories])
@beginning_balance.build_entries_from_categories
@beginning_balance.entries.build
render("new", :layout => false) and return
end
Expand Down Expand Up @@ -50,6 +50,13 @@ def update
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'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/items_controller.rb
Expand Up @@ -121,7 +121,7 @@ def lookup

def search
@keyword = params[:term]
@items = @keyword.nil? ? {} : current_company.items.name_or_code_like(@keyword).reject {|o| o.has_plu?}[0..10]
@items = @keyword.nil? ? {} : current_company.items.name_or_code_like(@keyword).reject {|o| !o.has_plu?}[0...10]
respond_to do |format|
format.html { render :layout => false }
format.js {
Expand Down
3 changes: 1 addition & 2 deletions app/models/beginning_balance.rb
Expand Up @@ -3,15 +3,14 @@ class BeginningBalance < Transaction
belongs_to :destination_warehouse, :class_name => "Warehouse", :foreign_key => :destination_id
has_many :entries, :foreign_key => :transaction_id, :dependent => :destroy
has_and_belongs_to_many :categories
accepts_nested_attributes_for :entries, :allow_destroy => true, :reject_if => proc { |a| a['quantity'].blank? }
validates_presence_of :number
before_save :assign_alter_stock

def category_name
@category_name || entries.first.try(:item).try(:category).try(:name)
end

def build_entries_from_categories(ids)
def build_entries_from_categories
categories.each do |cat|
cat.items.each do |item|
self.entries.build(:item_id => item.id)
Expand Down
1 change: 1 addition & 0 deletions app/models/entry.rb
Expand Up @@ -8,6 +8,7 @@ class Entry < ActiveRecord::Base
before_save :assign_item_id
before_save :assign_company_id
before_save :assign_value
after_save :track_details
has_many :details, :class_name => 'EntryDetail', :dependent => :destroy

named_scope :for_transactions, lambda { |ids|
Expand Down
3 changes: 2 additions & 1 deletion app/models/transaction.rb
Expand Up @@ -2,6 +2,7 @@ class Transaction < ActiveRecord::Base
belongs_to :company
belongs_to :transaction_type
has_many :entries
accepts_nested_attributes_for :entries, :allow_destroy => true, :reject_if => proc { |a| a['quantity'].blank? }

default_scope :order => "created_at"
named_scope :inward, :conditions => [ "origin_id IS NULL AND destination_id > ?", 0 ], :order => :created_at
Expand Down Expand Up @@ -44,7 +45,7 @@ class Transaction < ActiveRecord::Base
{ :conditions => [ "transactions.id NOT IN (?)", ids ] }
}

after_save :run_trackers
#after_save :run_trackers

def self.inward
transaction_origin_id_null.transaction_destination_id_not_null
Expand Down
3 changes: 1 addition & 2 deletions app/views/beginning_balances/_form.html.haml
Expand Up @@ -5,7 +5,7 @@
%h5 Sorry, but you have to at least have 1 warehouse to act as a default warehouse.
%h6= link_to "Click to add default warehouse", new_warehouse_path(:default => true)
- else
- semantic_form_for @beginning_balance, :url => beginning_balances_path do |f|
- semantic_form_for @beginning_balance do |f|
%fieldset.form_section
%legend Transaction data
- f.inputs do
Expand Down Expand Up @@ -53,7 +53,6 @@
:plain
$(function() {
$('#beginning_balance_category_ids').bind('multiselectclose', function(event, ui) {
var mrs = $(this).multiselect('getChecked');
var form = $(this).parents('form');
form.append('<input type="hidden" name="get_mrs" value="1"/>');
$.ajax({
Expand Down
1 change: 1 addition & 0 deletions app/views/beginning_balances/show.html.haml
Expand Up @@ -52,4 +52,5 @@
%td.actions= entry.quantity
%td.actions
= number_to_currency(entry.total_value, :unit => '', :delimiter => '.', :separator => ',')
%br
= "(@ #{number_to_currency(entry.value, :unit => '', :delimiter => '.', :separator => ',')})"
2 changes: 0 additions & 2 deletions public/javascripts/application.js
Expand Up @@ -211,7 +211,6 @@ $('.plu_input').live('click', function() {

$("form#search").live('submit', function() {
$(this).find('button[type=submit]').html('Searching...');
//.after("<span id='progress' style='font-style:italic;color:green;padding-left:5px;'>searching...</span>");
$.ajax({ url: this.action,
type: this.method,
data: $(this).serialize(),
Expand Down Expand Up @@ -302,7 +301,6 @@ $('input.entries_quantity, input.entries_value').live('keypress', function(e) {
if(e.keyCode == 13 && this.value != '') {
$('#add_entries').click();
$('#transaction_entries tbody tr:last td:first').children()[0].focus();
// set_autocomplete();
return false;
}
});
Expand Down

0 comments on commit 4ca9352

Please sign in to comment.