115 lines
3.9 KiB
Ruby
Executable File
115 lines
3.9 KiB
Ruby
Executable File
class Settings::TaxProfilesController < ApplicationController
|
|
load_and_authorize_resource except: [:create]
|
|
before_action :set_settings_tax_profile, only: [:show, :edit, :update, :destroy]
|
|
|
|
# GET /settings/tax_profiles
|
|
# GET /settings/tax_profiles.json
|
|
def index
|
|
@settings_tax_profiles = TaxProfile.all
|
|
tax_profiles = Lookup.collection_of("tax_profiles")
|
|
if !@settings_tax_profiles.nil?
|
|
@settings_tax_profiles.each_with_index do |setting_tax_profile, tax_index|
|
|
if !tax_profiles.nil?
|
|
tax_profiles.each do |group|
|
|
if setting_tax_profile.group_type == group[1]
|
|
@settings_tax_profiles[tax_index].group_type = group[0]
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# GET /settings/tax_profiles/1
|
|
# GET /settings/tax_profiles/1.json
|
|
def show
|
|
end
|
|
|
|
# GET /settings/tax_profiles/new
|
|
def new
|
|
@name = nil
|
|
@settings_tax_profile = TaxProfile.new
|
|
@tax_profiles = TaxProfile.all
|
|
end
|
|
|
|
# GET /settings/tax_profiles/1/edit
|
|
def edit
|
|
@settings_tax_profile = TaxProfile.find(params[:id])
|
|
@name = nil
|
|
if !@settings_tax_profile.nil?
|
|
@name = @settings_tax_profile.name
|
|
end
|
|
@tax_profiles = TaxProfile.all
|
|
end
|
|
|
|
# POST /settings/tax_profiles
|
|
# POST /settings/tax_profiles.json
|
|
def create
|
|
@settings_tax_profile = TaxProfile.new(settings_tax_profile_params)
|
|
@settings_tax_profile.created_by = current_login_employee.name
|
|
|
|
respond_to do |format|
|
|
if @settings_tax_profile.save
|
|
format.html { redirect_to settings_tax_profiles_path, notice: 'Tax profile was successfully created.' }
|
|
format.json { render :show, status: :created, location: @settings_tax_profile }
|
|
else
|
|
format.html { render :new }
|
|
format.json { render json: @settings_tax_profile.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PATCH/PUT /settings/tax_profiles/1
|
|
# PATCH/PUT /settings/tax_profiles/1.json
|
|
def update
|
|
respond_to do |format|
|
|
if @settings_tax_profile.update(settings_tax_profile_params)
|
|
format.html { redirect_to settings_tax_profiles_path, notice: 'Tax profile was successfully updated.' }
|
|
format.json { render :show, status: :ok, location: @settings_tax_profile }
|
|
else
|
|
format.html { render :edit }
|
|
format.json { render json: @settings_tax_profile.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /settings/tax_profiles/1
|
|
# DELETE /settings/tax_profiles/1.json
|
|
def destroy
|
|
customers = Customer.where("tax_profiles LIKE '%#{@settings_tax_profile.id}%'")
|
|
if customers.nil? || customers.empty?
|
|
@settings_tax_profile.destroy
|
|
flash[:notice] = 'Tax profile was successfully destroyed.'
|
|
render :json => {:status=> "Success", :url => settings_tax_profiles_url }.to_json
|
|
else
|
|
flash[:error] = 'Tax profile could not destroy! This record is using in somewhere.'
|
|
render :json => {:status=> "Error", :url => settings_tax_profiles_url }.to_json
|
|
end
|
|
# respond_to do |format|
|
|
# format.html { redirect_to settings_tax_profiles_url, notice: 'Tax profile was successfully destroyed.' }
|
|
# format.json { head :no_content }
|
|
# end
|
|
end
|
|
|
|
private
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_settings_tax_profile
|
|
@settings_tax_profile = TaxProfile.find(params[:id])
|
|
tax_profiles = Lookup.collection_of("tax_profiles")
|
|
if !@settings_tax_profile.nil?
|
|
if !tax_profiles.nil?
|
|
tax_profiles.each do |group|
|
|
if @settings_tax_profile.group_type == group[1]
|
|
@settings_tax_profile.group_type = group[0]
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# Never trust parameters from the scary internet, only allow the white list through.
|
|
def settings_tax_profile_params
|
|
params.require(:tax_profile).permit(:name, :group_type, :rate, :inclusive, :order_by, :created_by)
|
|
end
|
|
end
|