From 24294862e4923e844788dd45c3c725a482092a33 Mon Sep 17 00:00:00 2001 From: bohung Date: Tue, 6 Oct 2020 00:09:17 +0800 Subject: [PATCH] Fix bug.Add bill copy feature. --- .../admin/venue_admin_controller.rb | 2 +- .../venue_management_bills_controller.rb | 19 ++++++++-- .../admin/venue_managements_controller.rb | 2 +- app/models/venue_management_bill.rb | 35 ++++++++++++++----- .../venue_management_bills/_form.html.erb | 12 +++---- .../venue_management_bills/_index.html.erb | 21 ++++++++--- .../venue_management_bills/copy.html.erb | 5 +++ .../_index.html.erb | 18 ++++++++-- .../_index.html.erb | 18 ++++++++-- .../_index.html.erb | 18 ++++++++-- .../venue_managements/show_bill.html.erb | 4 +-- .../venue_managements/show_data.html.erb | 4 +-- config/locales/en.yml | 2 +- config/locales/zh_tw.yml | 2 +- config/routes.rb | 8 ++++- 15 files changed, 132 insertions(+), 38 deletions(-) create mode 100644 app/views/admin/venue_management_bills/copy.html.erb 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 @@
- +<% new_record = @venue_management_bill.new_record? && params["action"] != "copy" %>
@@ -37,14 +37,14 @@
- <%= f.datetime_picker :accounting_month, :no_label => true, :format=>"yyyy/MM", :new_record => @venue_management_bill.new_record? %> + <%= f.datetime_picker :accounting_month, :no_label => true, :format=>"yyyy/MM", :new_record => new_record %>
<%= f.select :bill_typeA, @venue_management_bill.class::BILLTYPE.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] },{},{:onchange=>"var $this=this;console.log($this.value);(function(){var obj=#{@venue_management_bill.class::BILLTYPE.map{|k,v| [k,v.map{|vv| [vv,I18n.t("vm_bill.#{vv}")]}.to_h]}.to_h.to_s.gsub('=>',':')};$($this).siblings('select').html($.map(obj[$this.value],function(v,k){return \'\'}).join(\' \'))})()"} %> - <% bill_typeB = @venue_management_bill.new_record? ? @venue_management_bill.class::BILLTYPE.values.first : @venue_management_bill.class::BILLTYPE[@venue_management_bill.bill_typeA] %> + <% bill_typeB = new_record ? @venue_management_bill.class::BILLTYPE.values.first : @venue_management_bill.class::BILLTYPE[@venue_management_bill.bill_typeA] %> <%= f.select :bill_typeB, bill_typeB.map { |v| [ I18n.t("vm_bill.#{v}"), v ] }, {}, {:onchange=> "var $this=this;(function(){if($this.value == 'other') $('#bill_other_field').removeClass('hidden');else $('#bill_other_field').addClass('hidden');})()"} %>
@@ -76,7 +76,7 @@ <%= f.select :caculation_basis_type, cbt.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] }, {}, :id=>'caculation_basis_type' %>
- <% caculation_basis_type = (@venue_management_bill.new_record? ? cbt.keys.first : @venue_management_bill.caculation_basis_type) %> + <% caculation_basis_type = (new_record ? cbt.keys.first : @venue_management_bill.caculation_basis_type) %>
<% cbt[caculation_basis_type].each do |k,v| %> <% no_margin = (v['no_margin'] rescue false) ? 'no_margin' : '' %> @@ -123,13 +123,13 @@
- <%= f.datetime_picker :deadline, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_bill.new_record? %> + <%= f.datetime_picker :deadline, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
- <%= f.datetime_picker :received_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_bill.new_record? %> + <%= f.datetime_picker :received_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
diff --git a/app/views/admin/venue_management_bills/_index.html.erb b/app/views/admin/venue_management_bills/_index.html.erb index d5581e6..fa4aba1 100644 --- a/app/views/admin/venue_management_bills/_index.html.erb +++ b/app/views/admin/venue_management_bills/_index.html.erb @@ -26,6 +26,7 @@ @@ -39,7 +40,7 @@ <%= bill.display_caculation_basis %> <%= bill.reason %> - <%= bill.amount %> + <%= bill.total_amount %> <%= bill.pay_date %> <%= bill.pay_method %> <%= bill.note %> @@ -56,9 +57,21 @@ <% if @venue_management.present? %>
-
- <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_bill_path(id: @venue_management.id), class: "btn btn-primary" %> -
+ <%= content_tag :div, class: "pagination pagination-centered" do %> + <%= paginate(@bills) %> +
+ <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_bill_path(id: @venue_management.id), class: "btn btn-primary" %> +
+ <% end %>
<% end %> + diff --git a/app/views/admin/venue_management_bills/copy.html.erb b/app/views/admin/venue_management_bills/copy.html.erb new file mode 100644 index 0000000..fa9a857 --- /dev/null +++ b/app/views/admin/venue_management_bills/copy.html.erb @@ -0,0 +1,5 @@ +<%= form_for @venue_management_bill, url: admin_venue_management_bills_path, html: {class: "form-horizontal main-forms"} do |f| %> +
+ <%= render :partial => 'form', locals: {f: f} %> +
+<% end %> diff --git a/app/views/admin/venue_management_contracts/_index.html.erb b/app/views/admin/venue_management_contracts/_index.html.erb index 49ec62a..9f7175c 100644 --- a/app/views/admin/venue_management_contracts/_index.html.erb +++ b/app/views/admin/venue_management_contracts/_index.html.erb @@ -54,9 +54,21 @@ <% if @venue_management.present? %>
-
- <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_contract_path(id: @venue_management.id), class: "btn btn-primary" %> -
+ <%= content_tag :div, class: "pagination pagination-centered" do %> + <%= paginate(@contracts) %> +
+ <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_contract_path(id: @venue_management.id), class: "btn btn-primary" %> +
+ <% end %>
<% end %> + \ No newline at end of file diff --git a/app/views/admin/venue_management_invitings/_index.html.erb b/app/views/admin/venue_management_invitings/_index.html.erb index 05e936b..3fb0a51 100644 --- a/app/views/admin/venue_management_invitings/_index.html.erb +++ b/app/views/admin/venue_management_invitings/_index.html.erb @@ -51,9 +51,21 @@ <% if @venue_management.present? %>
-
- <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_inviting_path(id: @venue_management.id), class: "btn btn-primary" %> -
+ <%= content_tag :div, class: "pagination pagination-centered" do %> + <%= paginate(@invitings) %> +
+ <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_inviting_path(id: @venue_management.id), class: "btn btn-primary" %> +
+ <% end %>
<% end %> + \ No newline at end of file diff --git a/app/views/admin/venue_management_memorabilias/_index.html.erb b/app/views/admin/venue_management_memorabilias/_index.html.erb index 4fe15df..3e44c75 100644 --- a/app/views/admin/venue_management_memorabilias/_index.html.erb +++ b/app/views/admin/venue_management_memorabilias/_index.html.erb @@ -44,9 +44,21 @@ <% if @venue_management.present? %>
-
- <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_memorabilia_path(id: @venue_management.id), class: "btn btn-primary" %> -
+ <%= content_tag :div, class: "pagination pagination-centered" do %> + <%= paginate(@memorabilias) %> +
+ <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_memorabilia_path(id: @venue_management.id), class: "btn btn-primary" %> +
+ <% end %>
<% end %> + diff --git a/app/views/venue_managements/show_bill.html.erb b/app/views/venue_managements/show_bill.html.erb index 2bfb29f..9c7fc73 100644 --- a/app/views/venue_managements/show_bill.html.erb +++ b/app/views/venue_managements/show_bill.html.erb @@ -41,8 +41,8 @@ <%= @venue_management_bill.reason %> - <%= t('vm_bill.amount') %> - <%= @venue_management_bill.amount %> + <%= t('vm_bill.total_amount') %> + <%= @venue_management_bill.total_amount %> <%= t('vm_bill.pay_date') %> diff --git a/app/views/venue_managements/show_data.html.erb b/app/views/venue_managements/show_data.html.erb index 892178f..d070f3d 100644 --- a/app/views/venue_managements/show_data.html.erb +++ b/app/views/venue_managements/show_data.html.erb @@ -354,7 +354,7 @@ "bill_type", "caculation_basis", "reason", - "amount", + "total_amount", "pay_date", "pay_method", "note" @@ -385,7 +385,7 @@ <%= bill.display_caculation_basis %> <%= bill.reason %> - <%= bill.amount %> + <%= bill.total_amount %> <%= bill.pay_date %> <%= bill.pay_method %> <%= bill.note %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 8a611d7..3d27273 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,5 @@ en: - + copy: Copy simple_captcha: placeholder: "" label: "" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 65a097b..25c56f5 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -1,5 +1,5 @@ zh_tw: - + copy: 複製 simple_captcha: placeholder: "" label: "" diff --git a/config/routes.rb b/config/routes.rb index e3e8bc7..051f262 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,7 +29,13 @@ Rails.application.routes.draw do resources :venue_management_item_contents resources :venue_management_invitings resources :venue_management_memorabilias - resources :venue_management_bills + resources :venue_management_bills do + collection do + scope "(:id)" do + get 'copy', to: 'venue_management_bills#copy' + end + end + end resources :venue_management_contracts do collection do post 'fetch_inviting'