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
#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] }

View File

@ -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)

View File

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

View File

@ -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 "")

View File

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

View File

@ -26,6 +26,7 @@
<ul class="nav nav-pills">
<% if can_edit_or_delete?(bill) %>
<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>
<% end %>
</ul>
@ -39,7 +40,7 @@
</td>
<td><%= bill.display_caculation_basis %></td>
<td><%= bill.reason %></td>
<td><%= bill.amount %></td>
<td><%= bill.total_amount %></td>
<td><%= bill.pay_date %></td>
<td><%= bill.pay_method %></td>
<td><%= bill.note %></td>
@ -56,9 +57,21 @@
<% if @venue_management.present? %>
<!-- footer -->
<div class="bottomnav clearfix">
<%= content_tag :div, class: "pagination pagination-centered" do %>
<%= paginate(@bills) %>
<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" %>
</div>
<% end %>
</div>
<!-- footer: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? %>
<!-- footer -->
<div class="bottomnav clearfix">
<%= content_tag :div, class: "pagination pagination-centered" do %>
<%= paginate(@contracts) %>
<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" %>
</div>
<% end %>
</div>
<!-- footer: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? %>
<!-- footer -->
<div class="bottomnav clearfix">
<%= content_tag :div, class: "pagination pagination-centered" do %>
<%= paginate(@invitings) %>
<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" %>
</div>
<% end %>
</div>
<!-- footer: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? %>
<!-- footer -->
<div class="bottomnav clearfix">
<%= content_tag :div, class: "pagination pagination-centered" do %>
<%= paginate(@memorabilias) %>
<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" %>
</div>
<% end %>
</div>
<!-- footer: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>
</tr>
<tr>
<th class="venue_managementive-title-field"><%= t('vm_bill.amount') %></th>
<td class="venue_managementive-title-value"><%= @venue_management_bill.amount %></td>
<th class="venue_managementive-title-field"><%= t('vm_bill.total_amount') %></th>
<td class="venue_managementive-title-value"><%= @venue_management_bill.total_amount %></td>
</tr>
<tr>
<th class="venue_managementive-title-field"><%= t('vm_bill.pay_date') %></th>

View File

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

View File

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

View File

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

View File

@ -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'