Class: RS::WaybillItem

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

Overview

ეს არის ზედნადების ხაზი საქონლისთვის.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bar_codeObject

Returns the value of attribute bar_code.



29
30
31
# File 'lib/rs/waybill.rb', line 29

def bar_code
  @bar_code
end

#excise_idObject

Returns the value of attribute excise_id.



29
30
31
# File 'lib/rs/waybill.rb', line 29

def excise_id
  @excise_id
end

#idObject

Returns the value of attribute id.



29
30
31
# File 'lib/rs/waybill.rb', line 29

def id
  @id
end

#priceObject

Returns the value of attribute price.



29
30
31
# File 'lib/rs/waybill.rb', line 29

def price
  @price
end

#prod_nameObject

Returns the value of attribute prod_name.



29
30
31
# File 'lib/rs/waybill.rb', line 29

def prod_name
  @prod_name
end

#quantityObject

Returns the value of attribute quantity.



29
30
31
# File 'lib/rs/waybill.rb', line 29

def quantity
  @quantity
end

#unit_idObject

Returns the value of attribute unit_id.



29
30
31
# File 'lib/rs/waybill.rb', line 29

def unit_id
  @unit_id
end

#unit_nameObject

Returns the value of attribute unit_name.



29
30
31
# File 'lib/rs/waybill.rb', line 29

def unit_name
  @unit_name
end

Class Method Details

.init_from_hash(hash) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rs/waybill.rb', line 47

def self.init_from_hash(hash)
  item = WaybillItem.new
  item.id = hash[:id]
  item.prod_name = hash[:w_name]
  item.unit_id = hash[:unit_id].to_i
  item.unit_name = hash[:unit_txt]
  item.quantity = hash[:quantity].to_f
  item.price = hash[:price].to_f
  item.bar_code = hash[:bar_code]
  item.excise_id = hash[:a_id] == '0' ? nil : hash[:a_id].to_i
  item
end

Instance Method Details

#to_xml(xml) ⇒ Object

აბრუნებს ამ ხაზის XML წარმოდგენას.

Parameters:

  • xml

    XML builder-ის კლასი



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rs/waybill.rb', line 33

def to_xml(xml)
  xml.GOODS do |b|
    b.ID (self.id ? self.id : 0)
    b.W_NAME self.prod_name
    b.UNIT_ID self.unit_id
    b.UNIT_TXT self.unit_name
    b.QUANTITY self.quantity
    b.PRICE self.price
    b.AMOUNT self.quantity * self.price
    b.BAR_CODE self.bar_code
    b.A_ID (self.excise_id ? self.excise_id : 0)
  end
end

#valid?Boolean

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/rs/waybill.rb', line 94

def valid?
  self.validate
  @validation_errors.empty?
end

#validateObject

ამოწმებს ამ კლასს შემდეგი შეცდომების არსებობაზე:

# საქონლის დასახელება უნდა იყოს მითითებული # შტრიხ-კოდი უნდა იყოს მითითებული # საქონლის ზომის ერთეული უნდა იყოს მითითებული # თუ ზომის ერთეულია “სხვა”, ზომის ერთეულის სახელიც უნდა იყოს მითითებული # რაოდენობა > 0 # ფასი >= 0



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rs/waybill.rb', line 68

def validate
  @validation_errors = {}
  if self.prod_name.nil? or self.prod_name.strip.empty?
    RS.append_validation_error(@validation_errors, :prod_name, 'საქონლის სახელი არაა განსაზღვრული')
  end
  if self.unit_id.nil?
    RS.append_validation_error(@validation_errors, :unit_id, 'ზომის ერთეული არაა განსაზღვრული')
  end
  if self.unit_id == RS::WaybillUnit::OTHERS and (self.unit_name.nil? or self.unit_name.strip.empty?)
    RS.append_validation_error(@validation_errors, :unit_name, 'ზომის ერთეულის სახელი არაა განსაზღვრული')
  end
  if self.quantity.nil? or self.quantity <= 0
    RS.append_validation_error(@validation_errors, :quantity, 'რაოდენობა უნდა იყოს მეტი 0-ზე')
  end
  if self.price.nil? or self.price < 0
    RS.append_validation_error(@validation_errors, :price, 'ფასი არ უნდა იყოს უარყოფითი')
  end
  if self.bar_code.nil? or self.bar_code.strip.empty?
    RS.append_validation_error(@validation_errors, :bar_code, 'საქონლის შტრიხ-კოდი უნდა იყოს განსაზღვრული')
  end
end

#validation_errorsObject



90
91
92
# File 'lib/rs/waybill.rb', line 90

def validation_errors
  @validation_errors
end