Fix bug.Add bill copy feature.

This commit is contained in:
BoHung Chiu 2020-10-06 00:09:17 +08:00
parent ff52810237
commit 24294862e4
15 changed files with 132 additions and 38 deletions

View File

@ -2,7 +2,7 @@
class Admin::VenueAdminController < OrbitAdminController class Admin::VenueAdminController < OrbitAdminController
#alias_method :org_datetime_picker, :datetime_picker #alias_method :org_datetime_picker, :datetime_picker
#include OrbitFormHelper #include OrbitFormHelper
before_action :set_calendar_types,only: [:edit,:new] before_action :set_calendar_types,only: [:edit,:new,:copy]
def set_calendar_types def set_calendar_types
@calendar_types = CalendarType.all.collect{|v| [v.title,v.id.to_s]} @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] } @module_pages = Page.where(:module => 'venue_management').collect{|p| [p.name,p.id] }

View File

@ -16,7 +16,7 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController
"bill_type", "bill_type",
"caculation_basis", "caculation_basis",
"reason", "reason",
"amount", "total_amount",
"pay_date", "pay_date",
"pay_method", "pay_method",
"note" "note"
@ -40,7 +40,22 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController
def edit def edit
@venue_management = VenueManagementMain.find(@venue_management_bill.venue_management_main_id) @venue_management = VenueManagementMain.find(@venue_management_bill.venue_management_main_id)
end 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 def update
@venue_management_bill.update_attributes(venue_management_bill_params) @venue_management_bill.update_attributes(venue_management_bill_params)

View File

@ -337,7 +337,7 @@ class Admin::VenueManagementsController < Admin::VenueAdminController
"bill_type", "bill_type",
"caculation_basis", "caculation_basis",
"reason", "reason",
"amount", "total_amount",
"pay_date", "pay_date",
"pay_method", "pay_method",
"note" "note"

View File

@ -18,7 +18,9 @@ class VenueManagementBill
f=field_values.shift(1) f=field_values.shift(1)
field_values.push(f[0]) field_values.push(f[0])
result += inner_product(field_values,percents) result += inner_product(field_values,percents)
result = result / 100", result = result / 100
if(result < 0)
result = 0",
"degree"=>" "degree"=>"
field_values.push(consumption) field_values.push(consumption)
dollardegrees.push(0) dollardegrees.push(0)
@ -26,17 +28,28 @@ class VenueManagementBill
f=field_values.shift(1) f=field_values.shift(1)
field_values.push(f[0]) field_values.push(f[0])
result += inner_product(field_values,dollardegrees) result += inner_product(field_values,dollardegrees)
", if(result < 0)
result = 0",
"actual_bill"=>" "actual_bill"=>"
result = bill_amount", result = bill_amount
if(result < 0)
result = 0",
"fixed"=>" "fixed"=>"
result = amount", result = amount
if(result < 0)
result = 0",
"taxable_present_value"=>" "taxable_present_value"=>"
result = taxable_tax", result = taxable_tax
if(result < 0)
result = 0",
"announced_land_values"=>" "announced_land_values"=>"
result = taxable_tax", result = taxable_tax
if(result < 0)
result = 0",
"other"=>" "other"=>"
result = amount" result = amount
if(result < 0)
result = 0"
} }
CACULATIONBASIS = {'revenue'=>"revenue", CACULATIONBASIS = {'revenue'=>"revenue",
"degree"=>"consumption", "degree"=>"consumption",
@ -88,9 +101,15 @@ class VenueManagementBill
# end # end
# end # 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 def display_caculation_basis
caculation_basis_val = eval("#{self.class::CACULATIONBASIS[self.caculation_basis_type]}") 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 end
def display_accounting_month def display_accounting_month
return (self.accounting_month.strftime("%Y-%m") rescue "") return (self.accounting_month.strftime("%Y-%m") rescue "")

View File

@ -28,7 +28,7 @@
</style> </style>
<!-- Input Area --> <!-- Input Area -->
<div class="input-area"> <div class="input-area">
<% new_record = @venue_management_bill.new_record? && params["action"] != "copy" %>
<!-- Module --> <!-- Module -->
<div class="tab-content module-area"> <div class="tab-content module-area">
<!-- Basic Module --> <!-- Basic Module -->
@ -37,14 +37,14 @@
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t('vm_bill.accounting_month') %></label> <label class="control-label muted"><%= t('vm_bill.accounting_month') %></label>
<div class="controls"> <div class="controls">
<%= 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 %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t('vm_bill.bill_type') %></label> <label class="control-label muted"><%= t('vm_bill.bill_type') %></label>
<div class="controls"> <div class="controls">
<%= 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 \'<option value=\"\'+k+\'\">\'+v+\'</option>\'}).join(\' \'))})()"} %> <%= 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 \'<option value=\"\'+k+\'\">\'+v+\'</option>\'}).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');})()"} %> <%= 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');})()"} %>
<div id="bill_other_field" class="tab-content language-area <%=@venue_management_bill.bill_typeB == 'other' ? '' : 'hidden'%>"> <div id="bill_other_field" class="tab-content language-area <%=@venue_management_bill.bill_typeB == 'other' ? '' : 'hidden'%>">
<div class="input-append"> <div class="input-append">
@ -76,7 +76,7 @@
<%= f.select :caculation_basis_type, cbt.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] }, {}, :id=>'caculation_basis_type' %> <%= f.select :caculation_basis_type, cbt.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] }, {}, :id=>'caculation_basis_type' %>
</div> </div>
</div> </div>
<% 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) %>
<div id="caculation_basis_content"> <div id="caculation_basis_content">
<% cbt[caculation_basis_type].each do |k,v| %> <% cbt[caculation_basis_type].each do |k,v| %>
<% no_margin = (v['no_margin'] rescue false) ? 'no_margin' : '' %> <% no_margin = (v['no_margin'] rescue false) ? 'no_margin' : '' %>
@ -123,13 +123,13 @@
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t('vm_bill.deadline') %></label> <label class="control-label muted"><%= t('vm_bill.deadline') %></label>
<div class="controls"> <div class="controls">
<%= 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 %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t('vm_bill.received_date') %></label> <label class="control-label muted"><%= t('vm_bill.received_date') %></label>
<div class="controls"> <div class="controls">
<%= 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 %>
</div> </div>
</div> </div>
</div> </div>

View File

@ -26,6 +26,7 @@
<ul class="nav nav-pills"> <ul class="nav nav-pills">
<% if can_edit_or_delete?(bill) %> <% if can_edit_or_delete?(bill) %>
<li><%= link_to t(:edit), edit_admin_venue_management_bill_path(bill.id) %></li> <li><%= link_to t(:edit), edit_admin_venue_management_bill_path(bill.id) %></li>
<li><%= link_to t(:copy), copy_admin_venue_management_bills_path(:id=>bill.id) %></li>
<li><a href="#" class="delete text-error" rel="/admin/venue_management_bills/<%=bill.id.to_s%>"><%= t(:delete_) %></a></li> <li><a href="#" class="delete text-error" rel="/admin/venue_management_bills/<%=bill.id.to_s%>"><%= t(:delete_) %></a></li>
<% end %> <% end %>
</ul> </ul>
@ -39,7 +40,7 @@
</td> </td>
<td><%= bill.display_caculation_basis %></td> <td><%= bill.display_caculation_basis %></td>
<td><%= bill.reason %></td> <td><%= bill.reason %></td>
<td><%= bill.amount %></td> <td><%= bill.total_amount %></td>
<td><%= bill.pay_date %></td> <td><%= bill.pay_date %></td>
<td><%= bill.pay_method %></td> <td><%= bill.pay_method %></td>
<td><%= bill.note %></td> <td><%= bill.note %></td>
@ -56,9 +57,21 @@
<% if @venue_management.present? %> <% if @venue_management.present? %>
<!-- footer --> <!-- footer -->
<div class="bottomnav clearfix"> <div class="bottomnav clearfix">
<%= content_tag :div, class: "pagination pagination-centered" do %>
<%= paginate(@bills) %>
<div class="action pull-right"> <div class="action pull-right">
<%= 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" %> <%= 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" %>
</div> </div>
<% end %>
</div> </div>
<!-- footer:end --> <!-- footer:end -->
<% end %> <% end %>
<style type="text/css">
.pagination-centered .pagination{
width: calc(100% - 6em);
float: left;
}
.main-list {
margin-bottom: 30px;
}
</style>

View File

@ -0,0 +1,5 @@
<%= form_for @venue_management_bill, url: admin_venue_management_bills_path, html: {class: "form-horizontal main-forms"} do |f| %>
<fieldset>
<%= render :partial => 'form', locals: {f: f} %>
</fieldset>
<% end %>

View File

@ -54,9 +54,21 @@
<% if @venue_management.present? %> <% if @venue_management.present? %>
<!-- footer --> <!-- footer -->
<div class="bottomnav clearfix"> <div class="bottomnav clearfix">
<%= content_tag :div, class: "pagination pagination-centered" do %>
<%= paginate(@contracts) %>
<div class="action pull-right"> <div class="action pull-right">
<%= 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" %> <%= 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" %>
</div> </div>
<% end %>
</div> </div>
<!-- footer:end --> <!-- footer:end -->
<% end %> <% end %>
<style type="text/css">
.pagination-centered .pagination{
width: calc(100% - 6em);
float: left;
}
.main-list {
margin-bottom: 30px;
}
</style>

View File

@ -51,9 +51,21 @@
<% if @venue_management.present? %> <% if @venue_management.present? %>
<!-- footer --> <!-- footer -->
<div class="bottomnav clearfix"> <div class="bottomnav clearfix">
<%= content_tag :div, class: "pagination pagination-centered" do %>
<%= paginate(@invitings) %>
<div class="action pull-right"> <div class="action pull-right">
<%= 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" %> <%= 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" %>
</div> </div>
<% end %>
</div> </div>
<!-- footer:end --> <!-- footer:end -->
<% end %> <% end %>
<style type="text/css">
.pagination-centered .pagination{
width: calc(100% - 6em);
float: left;
}
.main-list {
margin-bottom: 30px;
}
</style>

View File

@ -44,9 +44,21 @@
<% if @venue_management.present? %> <% if @venue_management.present? %>
<!-- footer --> <!-- footer -->
<div class="bottomnav clearfix"> <div class="bottomnav clearfix">
<%= content_tag :div, class: "pagination pagination-centered" do %>
<%= paginate(@memorabilias) %>
<div class="action pull-right"> <div class="action pull-right">
<%= 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" %> <%= 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" %>
</div> </div>
<% end %>
</div> </div>
<!-- footer:end --> <!-- footer:end -->
<% end %> <% end %>
<style type="text/css">
.pagination-centered .pagination{
width: calc(100% - 6em);
float: left;
}
.main-list {
margin-bottom: 30px;
}
</style>

View File

@ -41,8 +41,8 @@
<td class="venue_managementive-title-value"><%= @venue_management_bill.reason %></td> <td class="venue_managementive-title-value"><%= @venue_management_bill.reason %></td>
</tr> </tr>
<tr> <tr>
<th class="venue_managementive-title-field"><%= t('vm_bill.amount') %></th> <th class="venue_managementive-title-field"><%= t('vm_bill.total_amount') %></th>
<td class="venue_managementive-title-value"><%= @venue_management_bill.amount %></td> <td class="venue_managementive-title-value"><%= @venue_management_bill.total_amount %></td>
</tr> </tr>
<tr> <tr>
<th class="venue_managementive-title-field"><%= t('vm_bill.pay_date') %></th> <th class="venue_managementive-title-field"><%= t('vm_bill.pay_date') %></th>

View File

@ -354,7 +354,7 @@
"bill_type", "bill_type",
"caculation_basis", "caculation_basis",
"reason", "reason",
"amount", "total_amount",
"pay_date", "pay_date",
"pay_method", "pay_method",
"note" "note"
@ -385,7 +385,7 @@
</td> </td>
<td><%= bill.display_caculation_basis %></td> <td><%= bill.display_caculation_basis %></td>
<td><%= bill.reason %></td> <td><%= bill.reason %></td>
<td><%= bill.amount %></td> <td><%= bill.total_amount %></td>
<td><%= bill.pay_date %></td> <td><%= bill.pay_date %></td>
<td><%= bill.pay_method %></td> <td><%= bill.pay_method %></td>
<td><%= bill.note %></td> <td><%= bill.note %></td>

View File

@ -1,5 +1,5 @@
en: en:
copy: Copy
simple_captcha: simple_captcha:
placeholder: "" placeholder: ""
label: "" label: ""

View File

@ -1,5 +1,5 @@
zh_tw: zh_tw:
copy: 複製
simple_captcha: simple_captcha:
placeholder: "" placeholder: ""
label: "" label: ""

View File

@ -29,7 +29,13 @@ Rails.application.routes.draw do
resources :venue_management_item_contents resources :venue_management_item_contents
resources :venue_management_invitings resources :venue_management_invitings
resources :venue_management_memorabilias 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 resources :venue_management_contracts do
collection do collection do
post 'fetch_inviting' post 'fetch_inviting'