Skip to content

Instantly share code, notes, and snippets.

@patrickespake
Forked from dgoscn/us.rb
Last active June 6, 2019 15:04
Show Gist options
  • Save patrickespake/c8be870c722add8fcf75a2ea9806e1eb to your computer and use it in GitHub Desktop.
Save patrickespake/c8be870c722add8fcf75a2ea9806e1eb to your computer and use it in GitHub Desktop.
class Administration::ContractsController < Administration::BaseController
def new
@company = Company.find(params[:company_id])
@contract = Contract.new
@contract.distance_fees.build
@contract.contract_authorizations.build
@contract.initial_charge = current_admin_user.levoo_unit.present? ? current_admin_user.levoo_unit.setting.initial_charge : Setting.first.initial_charge
@contract.extra_mileage_threshold = current_admin_user.levoo_unit.present? ? current_admin_user.levoo_unit.setting.extra_mileage_threshold : Setting.first.extra_mileage_threshold
@contract.extra_mileage_value = current_admin_user.levoo_unit.present? ? current_admin_user.levoo_unit.setting.extra_mileage_value : Setting.first.extra_mileage_value
binding.pry
end
def create
@company = Company.find(params[:company_id])
@contract = Contract.create(contract_params)
if @contract.valid?
redirect_to administration_companies_path, notice: t('models.general.company.notice.create.success')
else
render :new
end
end
private
def contract_params
params
.require(:contract)
.permit(:identifier,
:total_value,
:deliverer_value,
:charge_origin,
:charge_back_to_origin,
:login,
:password,
:company_id,
:category_contract,
:initial_charge,
:extra_mileage_threshold,
:extra_mileage_value,
contract_authorizations_attributes: [:employee_id],
distance_fees_attributes: [:distance,
:price,
:levoo_percentage,
:contract_id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment