Last active
August 29, 2015 14:05
-
-
Save guipdutra/567f9c3570b56a632434 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_fields(f, rand, data_type, column, operator) | |
out = '' | |
if ["Date", "DateTime"].include?(data_type) | |
out << f.select(:operator, hash_to_options(FilterConstants::DATE_OPERATOR), { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << f.text_field(:condition, :value => (f.object.condition.to_date.to_s_br rescue nil), :class => "text mini js c_#{rand} format[date]") | |
elsif data_type == "Month" | |
out << f.select(:operator, hash_to_options(FilterConstants::DATE_OPERATOR), { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << f.text_field(:condition, :value => (I18n.l(f.object.condition.to_date, :format => :small_month_and_year) rescue nil), :class => "text mini js c_#{rand} format[competence]") | |
elsif data_type == "Match" | |
text = if column.include?("cpf") || column.include?('cnpj') | |
format = column.include?("cpf") ? "cpf" : "cnpj" | |
f.text_field(:condition, :class => "text mini js c_#{rand} format[#{format}]") | |
elsif column == "city_registration" | |
f.text_field(:condition, :class => "text mini js c_#{rand}") | |
end | |
out << f.select(:operator, hash_to_options(FilterConstants::MATCH_OPERATOR), { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << text | |
elsif data_type == "String" | |
out << f.select(:operator, hash_to_options(FilterConstants::STRING_OPERATOR), { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << f.text_field(:condition, :class => "text mini js c_#{rand}") | |
elsif data_type == "Contains" | |
out << f.select(:operator, hash_to_options(FilterConstants::CONTAINS_OPERATOR), { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << f.text_field(:condition, :class => "text mini js c_#{rand}") | |
elsif data_type == "Fixnum" || data_type == "Percent" || data_type == "Computed" | |
out << f.select(:operator, hash_to_options(FilterConstants::FIXNUM_OPERATOR), { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << f.text_field(:condition, :class => "text mini js c_#{rand}") | |
elsif data_type == "Cities" | |
out << f.select(:operator, hash_to_options(FilterConstants::LOCATION_OPERATOR), { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << if column == "city_hall_id" | |
f.select(:condition, CityHall.all.collect { |c| [c.city.to_s, c.id] }, { :selected => f.object.condition }, { :class => "text mini c_#{rand}" }) | |
else | |
f.select(:condition, CityHall.all.collect { |c| [c.city.to_s, c.city_id] }, { :selected => f.object.condition }, { :class => "text mini c_#{rand}" }) | |
end | |
elsif data_type == "Presence" | |
out << f.select(:operator, hash_to_options(FilterConstants::PRESENCE_OPERATOR), { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << f.select(:condition, FilterConstants::PRESENCE_CONDITIONS.collect { |k, v| [v, k] }, { :selected => f.object.condition }, { :class => "text mini c_#{rand}" }) | |
elsif data_type == "Boolean" | |
out << f.select(:operator, hash_to_options(FilterConstants::BOOLEAN_OPERATOR), { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << f.select(:condition, FilterConstants::BOOLEAN_CONDITIONS.collect { |k, v| [v, k] }, { :selected => f.object.condition }, { :class => "text mini c_#{rand}" }) | |
elsif data_type == "Status" | |
binding.pry | |
enum = if column == "stub_status" | |
options_for_select(Stub::STATES.collect { |k| [I18n.t("stubs.status.#{k}"), k.to_s] }, f.object.condition) | |
elsif column == "state" | |
options_for_select(ServiceOrderStep::TEMPLATES.keys.concat([:new, :closed, :canceled]).collect { |k| [I18n.t("service_orders.states.#{k}"), k.to_s] }, f.object.condition) | |
elsif f.object.item.serie == "Taxpayer" | |
options_for_select(statuses_for_ccm(true), f.object.condition.to_i) | |
else | |
options_for_select([["Normal", "issued"], ["Cancelada", "cancelled"], ["Substituída", "substituted"]], f.object.condition) | |
end | |
out << f.select(:operator, hash_to_options(FilterConstants::MATCH_OPERATOR).reverse, { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << f.select(:condition, enum, { :selected => f.object.condition }, { :class => "text mini c_#{rand}" }) | |
elsif data_type == "City" | |
city = current_user.has_role?("system_admin") ? CityHall.all : [current_user.city_hall] | |
city = city.collect { |c| [c.city.to_s, c.city_id] } | |
city = [["Minha Cidade", "my_city"]].concat(city) if current_user.has_role?("system_admin") | |
out << f.select(:operator, hash_to_options(FilterConstants::LOCATION_OPERATOR), { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << f.select(:condition, city, { :selected => f.object.condition }, { :class => "text mini c_#{rand}" }) | |
elsif data_type == "Enumeration" | |
enum = if column == "operation_nature" | |
options_for_select(hash_to_options(Nfe::OPERATION_NATURE), f.object.condition.to_i) | |
elsif column == "doc_type" | |
hash_to_options(Underwriting::DOC_TYPE) | |
elsif column == "state" | |
ary = [["Normal", "issued"], ["Rejeitada", "rejected"], ["Cancelada", "cancelled"], ["Substituída", "substituted"], ["Em Dívida", "debitted"]] | |
if current_user.city? && current_city_hall.cancel_on_current_competence? | |
ary << ["Cancelada (PA)", "pa_cancelled"] | |
end | |
options_for_select(ary, f.object.condition) | |
elsif column == "situation" | |
options_for_select(Underwriting::STATUSES.collect { |k| [I18n.t("underwriting.statuses.#{k}"), k.to_s] }, f.object.condition) | |
elsif column == "divergence_level" | |
options_for_select([["Em aberto", "NULL"], ["Em acordo", 1], ["Div. Moderada", 2], ["Div. Séria", 3]], f.object.condition.to_i) | |
elsif column == "provider" | |
options_for_select([["Prestador", 1], ["Tomador", 0]], f.object.condition.to_i) | |
elsif column == "provider_type" || column == "receiver_type" || column == "taxpayer_type" | |
options_for_select([["Empresa", "company"], ["Profissional Liberal", "profissional_liberal"], ["Autônomo", "autonomo"]], f.object.condition) | |
elsif column == "payment_method" | |
options_for_select(Stub::PAYMENT_METHODS.collect { |k,v| [I18n.t("stubs.payment_methods.#{k}"), v] }, f.object.condition) | |
elsif column == "special_regimen" | |
options_for_select(TaxpayerConstants::SPECIAL_REGIMEN.collect { |k,v| [v.capitalize, k] }, f.object.condition.to_i) | |
elsif column == "type" | |
pf_type = TaxpayerConstants::PF_TYPE.collect { |k,v| [v.capitalize, "Taxpayer::#{k}"] } | |
taxpayer_type = TaxpayerConstants::TAXPAYER_TYPE.collect { |k,v| [v.capitalize, k] } | |
options_for_select(pf_type.concat(taxpayer_type), f.object.condition) | |
elsif column == "education" | |
options_for_select(TaxpayerConstants::EDUCATION.collect { |k,v| [v.capitalize, k] }, f.object.condition) | |
end | |
out << f.select(:operator, hash_to_options(FilterConstants::MATCH_OPERATOR).reverse, { :selected => operator }, { :class => "text mini o_#{rand}" }) | |
out << f.select(:condition, enum, { :selected => f.object.condition }, { :class => "text mini c_#{rand}" }) | |
end | |
out | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment