Created
October 8, 2019 20:44
-
-
Save victorgiraldes/0c9d0d55c8d4f0248990afe6c9bfeff3 to your computer and use it in GitHub Desktop.
This file contains 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 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