Class: ProcessDeclIva::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/process_decl_iva.rb

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



12
13
14
15
# File 'lib/process_decl_iva.rb', line 12

def initialize
  @year = ENV.fetch("Y")
  @quarter = ENV.fetch("T")
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/process_decl_iva.rb', line 17

def run
  reporte = ask("Introduza o reporte do trimestre passado [0.00]")
  reporte = 0.0 if reporte.to_f.zero?

  reservations_csv_path = prompt_file("Indique o ficheiro CSV com as reservas do ultimo trimestre", "docs/#{@year}/reservasT#{@quarter}.csv")

  expenses_csv_path = prompt_file("Indique o ficheiro CSV com as despesas do ultimo trimestre", "docs/#{@year}/faturasT#{@quarter}.csv")

  other_commissions = ask("Indique se ocorreu em algumas outras comissoes no trimestre anterior [0.00]")
  other_commissions = 0.0 if other_commissions.to_f.zero?

  reservations_csv = File.read(reservations_csv_path)
  expenses_csv = File.read(expenses_csv_path)

  reservations_service = ProcessReservations::Talkguest.new(reservations_csv)

  expenses_service = ProcessExpenses::EFatura.new(expenses_csv)

  reservations_service.call
  expenses_service.call

  Calculate.new(
    from_last_period: reporte.to_f,
    total_vat: expenses_service.total_vat,
    other_commissions: other_commissions.to_f,
    sales_vat: reservations_service.sales_vat,
    sales_amount: reservations_service.sales_amount
  ).call
end