creating sync with billing

This commit is contained in:
olegphenomenon 2023-01-11 12:25:49 +02:00
parent 162647acba
commit 0a4444b556
9 changed files with 577 additions and 60 deletions

View file

@ -31,4 +31,22 @@ module Invoice::Cancellable
def not_cancelled?
!cancelled?
end
def cancel_manualy
account_activity = AccountActivity.find_by(invoice_id: id)
account_activity_dup = account_activity.dup
account_activity_dup.sum = -account_activity.sum.to_i
account_activity_dup.save
account_activity.update(invoice_id: nil)
account_activity_dup.update(invoice_id: nil)
mark_cancelled_payment_order
account_activity.save && account_activity_dup.save
end
private
def mark_cancelled_payment_order
payment_order = payment_orders.last
payment_order.update(notes: 'Cancelled')
end
end

View file

@ -23,4 +23,34 @@ module Invoice::Payable
def unpaid?
!paid?
end
def process_payment(**options)
payment = options[:payment_type].constantize.new(invoice: self)
payment.response = options[:everypay_response]
payment.status = options[:payment_status]
payment.save!
bank_transaction = payment.base_transaction(sum: options[:sum],
paid_at: options[:transaction_time] || Time.zone.now,
buyer_name: buyer_name)
bank_transaction.bind_invoice(number)
end
def autobind_manually
return if paid?
bank_statement = BankStatement.new(
bank_code: Setting.registry_bank_code,
iban: Setting.registry_iban
)
bank_statement.bank_transactions.build(
description: description,
sum: total,
reference_no: reference_no,
paid_at: Time.zone.now.to_date,
currency: 'EUR'
)
bank_statement.save!
bank_statement.bind_invoices(manual: true)
end
end