Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save victorgiraldes/0c9d0d55c8d4f0248990afe6c9bfeff3 to your computer and use it in GitHub Desktop.
Save victorgiraldes/0c9d0d55c8d4f0248990afe6c9bfeff3 to your computer and use it in GitHub Desktop.
def create
@block_edit = false
@bank_debit = current_company.bank_debits.new(permitted_params[:bank_debit])
if @bank_debit.save
@bank_debit.update_attribute(:user_id, current_user.id)
current_user.up_score!(1.3) if current_user.Potencial?
#plot debit
plots_debit(params[:bank_debit][:plots], params[:plots_count].to_i, @bank_debit)
# replicate debit
repeat_debit(params[:repeat_number].to_i, params[:repeat_method].to_i, @bank_debit)
redirect_to cash_path, notice: 'Lançamento realizado com sucesso'
else
render 'new'
end
end
def repeat_debit(repeat_number, repeat_method, debit)
bank = debit.bank
if repeat_number >= 1
i = 1
for i in (i...repeat_number) do
d = repeat_method == 7 ? (i * repeat_method).days : i.months
current_company.bank_debits.create(debit.attributes.merge({ id: nil, description: "#{debit.description} #{i + 1}/#{repeat_number}", paid_at: debit.paid_at + d }))
end
debit.update_attribute(:description, "#{debit.description} 1/#{repeat_number}") if debit.description === debit.description
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment