Class: Billing::IssueFiscalDoc

Inherits:
Object
  • Object
show all
Extended by:
Resque::Plugins::ExtfaceLonelyDevice
Defined in:
app/jobs/billing/issue_fiscal_doc.rb

Constant Summary

Constants included from Resque::Plugins::ExtfaceLonelyDevice

Resque::Plugins::ExtfaceLonelyDevice::LOCK_TIMEOUT

Class Method Summary collapse

Methods included from Resque::Plugins::ExtfaceLonelyDevice

around_perform, before_perform, can_lock_queue?, lock_timeout, redis_key, reenqueue, requeue_interval, unlock_queue

Class Method Details

.perform(bill_id) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/jobs/billing/issue_fiscal_doc.rb', line 76

def self.perform(bill_id)
  bill = Bill.find(bill_id)
  qname = "extface_#{bill.extface_job.device_id}"
  wjs = Resque::Worker.working.find_all{ |w| w.job && w.job['queue'] == qname }
  
  p "############################"
  p "d: #{bill.extface_job.device_id} Issue Fiscal Doc ##{bill_id}, job: #{bill.extface_job_id}, wjs: #{wjs.inspect}"
  p "____________________________"
  p "active jobs: #{bill.extface_job.device.jobs.active.count}"
  

    bill.extface_job.runtime do |s|
      return unless bill.fiscalizable?
      operator_mapping = bill.find_operator_mapping_for(s)
      s.notify "Fiscal Doc Start"
      s.autofix_unclosed_doc
      s.open_fiscal_doc(operator_mapping.try(:mapping), operator_mapping.try(:pwd))
      s.notify "Register Sale"
      bill.charges.each do |charge|
        neto, percent_ratio = nil, nil, nil
        if modifier = charge.modifier
          neto = modifier.fixed_value
          percent_ratio = modifier.percent_ratio unless neto.present?
        end
        if charge.price.zero? #printing comments with zero charges (TODO check zero charges allowed?)
          s.add_comment charge.text
        else
          s.add_sale(
            s.class::SaleItem.new(
              price: charge.price.to_f, 
              text1: charge.name,
              text2: charge.description,
              tax_group: charge.find_tax_group_mapping_for(s), #find tax group mapping by ratio , not nice
              qty: charge.qty,
              neto: neto,
              percent_ratio: percent_ratio #TODO check format
            )
          )
        end
      end
      if global_modifier_value = bill.global_modifier_value
        s.notify "Register Global Modifier"
        s.add_total_modifier global_modifier_value.to_f 
      end
      s.notify "Register Payment"
      bill.payments.each do |payment|
        s.add_payment payment.value.to_f, payment.find_payment_type_mapping_for(s)
      end
      s.notify "Close Fiscal Receipt"
      s.close_fiscal_doc
      s.notify "Fiscal Doc End"
    end
rescue Resque::TermException
  reenqueue(bill_id)
end

.redis_key(bill_id) ⇒ Object



72
73
74
# File 'app/jobs/billing/issue_fiscal_doc.rb', line 72

def self.redis_key(bill_id)
  "extface_#{Bill.find(bill_id).extface_job.device_id}"
end