Яuбy / Говнокод #2422 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
class FinancialEventObserver < ActiveRecord::Observer
  observe Payment, Invoice
  def before_save(model)
    event = nil        
    if model.class == Payment
      if model.new_record?        
        event = FinancialEvent.new(:event => FinancialEvent::Event::PAYMENT_INVOICE,
        :arguments => {:client_name => model.invoice.client.short_name, :invoice_number => model.invoice.invoice_number},
          :company_id=>model.invoice.client.company.id)
      end
    elsif model.class == Invoice
      i = Invoice.find_by_id model.id      
      if model.new_record? or i.status != model.status        
        if model.status == Invoice::Status::ESTIMATE
          event = FinancialEvent.new(:event => FinancialEvent::Event::ESTIMATE_SEND,
        :arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},
            :company_id=>model.client.company.id)
        elsif model.status == Invoice::Status::APPROVED
          event = FinancialEvent.new(:event => FinancialEvent::Event::ESTIMATE_APPROVED,
        :arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},
            :company_id=>model.client.company.id)
        elsif model.status == Invoice::Status::REJECTED
          event = FinancialEvent.new(:event => FinancialEvent::Event::ESTIMATE_REJECTED,
        :arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},
            :company_id=>model.client.company.id)
        elsif model.status == Invoice::Status::SEND
          event = FinancialEvent.new(:event => FinancialEvent::Event::INVOICE_SEND,
        :arguments => {:client_name => model.client.short_name, :invoice_number => model.invoice_number},
            :company_id=>model.client.company.id)            
        end
      elsif !model.new_record? and i.state != model.state
        if model.state == Invoice::State::DELETED
          event = FinancialEvent.new(:event => FinancialEvent::Event::INVOICE_DELETED,
        :arguments => {:invoice_number => model.invoice_number},
            :company_id=>model.client.company.id)
        end
      end    
    end
    event.eventable = model.requester unless event.blank? 
    event.save unless event.blank?
    
  end
  def before_destroy(model)
    if model.class == Payment
      event = FinancialEvent.new(:event => FinancialEvent::Event::PAYMENT_DELETED,
        :arguments => {:invoice_number => model.invoice.invoice_number},
      :company_id=>model.invoice.client.company.id)
      event.eventable = model.requester
      event.save
    end    
  end
end

о боже, зачем я открыл этот файл?

Запостил: rakoth3d rakoth3d, (Updated )

Комментарии (5) RSS

  • elsif model.class == Invoice
    i = Invoice.find_by_id model.id

    оо, зацените, просто отжиг
    Ответить
    • ага. а после этого еще и проверки
      i.status != model.status
      и
      i.state != model.state

      типа контрольный выстрел. чтобы смотрящий на это уже не надеялся ни на что хорошее 🙂
      Ответить
      • Предыдущее сообщение считать недействительным.
        Ответить
  • пизда, скриптушня, по вербозности положившая на лопатки яжу и обжси вместе взятые. как такое возможно??
    Ответить

Добавить комментарий

Из-за тебя ушел bormand, guest!

    А не использовать ли нам bbcode?


    8