diff --git a/app/controllers/admin/venue_admin_controller.rb b/app/controllers/admin/venue_admin_controller.rb index f564785..ee18759 100644 --- a/app/controllers/admin/venue_admin_controller.rb +++ b/app/controllers/admin/venue_admin_controller.rb @@ -2,7 +2,7 @@ class Admin::VenueAdminController < OrbitAdminController #alias_method :org_datetime_picker, :datetime_picker #include OrbitFormHelper - before_action :set_calendar_types,only: [:edit,:new] + before_action :set_calendar_types,only: [:edit,:new,:copy] def set_calendar_types @calendar_types = CalendarType.all.collect{|v| [v.title,v.id.to_s]} @module_pages = Page.where(:module => 'venue_management').collect{|p| [p.name,p.id] } diff --git a/app/controllers/admin/venue_management_bills_controller.rb b/app/controllers/admin/venue_management_bills_controller.rb index 4c40b8a..a23e29d 100644 --- a/app/controllers/admin/venue_management_bills_controller.rb +++ b/app/controllers/admin/venue_management_bills_controller.rb @@ -16,7 +16,7 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController "bill_type", "caculation_basis", "reason", - "amount", + "total_amount", "pay_date", "pay_method", "note" @@ -40,7 +40,22 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController def edit @venue_management = VenueManagementMain.find(@venue_management_bill.venue_management_main_id) end - + def copy + @venue_management_bill_to_copy = VenueManagementBill.find(params[:id]) + attributes = @venue_management_bill_to_copy.attributes.except("_id","updated_at","created_at") + VenueManagementBill.fields.each do |k,v| + if v.options[:localize] + attributes.delete k + attributes[k+"_translations"] = @venue_management_bill_to_copy[k] + elsif attributes[k].class == Hash + attributes[k] = BSON::Document.new(attributes[k]) + end + end + + @venue_management_bill = VenueManagementBill.new(attributes) + #render :html =>attributes and return + @venue_management = VenueManagementMain.find(@venue_management_bill_to_copy.venue_management_main_id) + end def update @venue_management_bill.update_attributes(venue_management_bill_params) diff --git a/app/controllers/admin/venue_managements_controller.rb b/app/controllers/admin/venue_managements_controller.rb index 050b55a..727a234 100644 --- a/app/controllers/admin/venue_managements_controller.rb +++ b/app/controllers/admin/venue_managements_controller.rb @@ -337,7 +337,7 @@ class Admin::VenueManagementsController < Admin::VenueAdminController "bill_type", "caculation_basis", "reason", - "amount", + "total_amount", "pay_date", "pay_method", "note" diff --git a/app/models/venue_management_bill.rb b/app/models/venue_management_bill.rb index fc56e1a..5189270 100644 --- a/app/models/venue_management_bill.rb +++ b/app/models/venue_management_bill.rb @@ -18,7 +18,9 @@ class VenueManagementBill f=field_values.shift(1) field_values.push(f[0]) result += inner_product(field_values,percents) - result = result / 100", + result = result / 100 + if(result < 0) + result = 0", "degree"=>" field_values.push(consumption) dollardegrees.push(0) @@ -26,17 +28,28 @@ class VenueManagementBill f=field_values.shift(1) field_values.push(f[0]) result += inner_product(field_values,dollardegrees) - ", + if(result < 0) + result = 0", "actual_bill"=>" - result = bill_amount", + result = bill_amount + if(result < 0) + result = 0", "fixed"=>" - result = amount", + result = amount + if(result < 0) + result = 0", "taxable_present_value"=>" - result = taxable_tax", + result = taxable_tax + if(result < 0) + result = 0", "announced_land_values"=>" - result = taxable_tax", + result = taxable_tax + if(result < 0) + result = 0", "other"=>" - result = amount" + result = amount + if(result < 0) + result = 0" } CACULATIONBASIS = {'revenue'=>"revenue", "degree"=>"consumption", @@ -88,9 +101,15 @@ class VenueManagementBill # end # end # end + # after_save do |record| + # venue_management_main = record.venue_management_main + # if !venue_management_main.venue_management_bill_ids.include?(record.id) + # venue_management_main.update(venue_management_main.venue_management_bill_ids.push(record.id)) + # end + # end def display_caculation_basis caculation_basis_val = eval("#{self.class::CACULATIONBASIS[self.caculation_basis_type]}") - return "#{I18n.t("vm_bill.#{self.caculation_basis_type}")}: #{caculation_basis_val}" + return "#{I18n.t("vm_bill.#{self.class::CACULATIONBASIS[self.caculation_basis_type]}")}: #{caculation_basis_val}" end def display_accounting_month return (self.accounting_month.strftime("%Y-%m") rescue "") diff --git a/app/views/admin/venue_management_bills/_form.html.erb b/app/views/admin/venue_management_bills/_form.html.erb index e5a6ab5..23254a0 100644 --- a/app/views/admin/venue_management_bills/_form.html.erb +++ b/app/views/admin/venue_management_bills/_form.html.erb @@ -28,7 +28,7 @@