invoicing_payments_processing 1.1.61 → 1.1.62

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7019008952c4a101402f3437fb2c7e72a64987f
4
- data.tar.gz: 32eb0417161011cec4032e3f72aaf4f8d2f0d75e
3
+ metadata.gz: 4274c11ebe44a85852da2cd471b1d2ccbd088266
4
+ data.tar.gz: b6b303e495c9ada9185cb9abc26d270debc6487f
5
5
  SHA512:
6
- metadata.gz: 161824735dffd0670ca5d5d838121788ab3e1b36fc651cbfd401f0cbcf182c26cf6bb436dd131c5a31f787c5c507a8fa11b1ab7b35c6513da505af9c437c91f9
7
- data.tar.gz: 1a40cfdd633075be2a2ccd1da1d3b047b16b8b582fcb1b03116de1b6e529336d6ce7afb3ca7bd5bfefd20064e10b9dfcebda6b1b163ca1a0c8706bab214eb840
6
+ metadata.gz: c144e34feb9b8ae90c4514a27e3fe9d042d1a50ca3ecd7577307e26dd8858c7689cf7dd8d647b8cf28193d33f51d7da8bcf057ffb29a0c9fb336de50dea5cab3
7
+ data.tar.gz: 187387a945ab22e3e38b1f35a5884b10bcddb50ba5b218b1730dce093ab67b751cb014b887c77bbd66b567515e3ac81390cd3bf6d65a4606994a5300a0862c9d
@@ -24,7 +24,7 @@ module BlackStack
24
24
  "where x.id_client='#{self.client.id}' " +
25
25
  "and x.product_code='#{self.product_code}' "
26
26
  end
27
-
27
+ #puts "Balance.calculate:q:#{q}:."
28
28
  row = DB[q].first
29
29
  self.amount = row[:amount].to_f
30
30
  self.credits = row[:credits].to_f
@@ -51,7 +51,9 @@ module BlackStack
51
51
  end
52
52
 
53
53
  # crea/actualiza un registro en la tabla movment, reduciendo la cantidad de creditos y saldo que tiene el cliente, para el producto indicado en product_code.
54
- def consume(product_code, number_of_credits=1, description=nil)
54
+ def consume(product_code, number_of_credits=1, description=nil, datetime=nil)
55
+ dt = datetime.nil? ? now() : datetime.to_time.to_sql
56
+
55
57
  # create the consumtion
56
58
  total_credits = 0.to_f - BlackStack::Balance.new(self.id, product_code).credits.to_f
57
59
  total_amount = 0.to_f - BlackStack::Balance.new(self.id, product_code).amount.to_f
@@ -60,7 +62,7 @@ module BlackStack
60
62
  cons = BlackStack::Movement.new
61
63
  cons.id = guid()
62
64
  cons.id_client = self.id
63
- cons.create_time = now()
65
+ cons.create_time = dt
64
66
  cons.type = BlackStack::Movement::MOVEMENT_TYPE_CANCELATION
65
67
  cons.description = description.nil? ? 'Consumption' : description
66
68
  cons.paypal1_amount = 0
@@ -121,7 +121,12 @@ module BlackStack
121
121
 
122
122
  # Returns the number of credits assigned in the movement that have been consumed.
123
123
  # The movment must be a payment or a bonus
124
- def credits_consumed()
124
+ #
125
+ # registraton_time: consider only movements before this time. If it is nil, this method will consider all the movements.
126
+ #
127
+ def credits_consumed(registraton_time=nil)
128
+ # le agrego 365 dias a la fecha actual, para abarcar todas las fechas ocurridas hasta hoy seguro
129
+ registraton_time = (Time.now() + 365*24*60*60).to_time if registraton_time.nil?
125
130
  # the movment must be a payment or a bonus
126
131
  raise 'Movement must be either a payment or a bonus' if self.type != MOVEMENT_TYPE_ADD_PAYMENT && self.type != MOVEMENT_TYPE_ADD_BONUS
127
132
  #puts
@@ -131,7 +136,8 @@ module BlackStack
131
136
  self.client.movements.select { |o|
132
137
  (o.type == MOVEMENT_TYPE_ADD_PAYMENT || o.type == MOVEMENT_TYPE_ADD_BONUS) &&
133
138
  o.credits.to_f < 0 &&
134
- o.product_code.upcase == self.product_code.upcase
139
+ o.product_code.upcase == self.product_code.upcase &&
140
+ o.create_time.to_time <= registraton_time.to_time
135
141
  }.sort_by { |o| o.create_time }.each { |o|
136
142
  paid += (0.to_f - o.credits.to_f)
137
143
  break if o.id.to_guid == self.id.to_guid
@@ -140,7 +146,8 @@ module BlackStack
140
146
  # calculo los credito para este producto, desde el primer dia; incluyendo cosumo, expiraciones, ajustes.
141
147
  consumed = self.client.movements.select { |o|
142
148
  o.credits.to_f > 0 &&
143
- o.product_code.upcase == self.product_code.upcase
149
+ o.product_code.upcase == self.product_code.upcase &&
150
+ o.create_time.to_time <= registraton_time.to_time
144
151
  }.inject(0) { |sum, o| sum.to_f + o.credits.to_f }.to_f
145
152
  #puts "consumed:#{consumed.to_s}:."
146
153
  # calculo los creditos de este movimiento que voy a cancelar
@@ -184,7 +191,10 @@ module BlackStack
184
191
 
185
192
  # credits expiration
186
193
  def expire(registraton_time=nil, desc='Expiration Because Allocation is Renewed')
187
- credits_consumed = self.credits_consumed
194
+ #puts
195
+ #puts "registraton_time:#{registraton_time.to_s}:."
196
+ credits_consumed = self.credits_consumed(registraton_time)
197
+ #puts "credits_consumed:#{credits_consumed.to_s}:."
188
198
  #
189
199
  self.expiration_start_time = now()
190
200
  self.expiration_tries = self.expiration_tries.to_i + 1
@@ -192,6 +202,8 @@ module BlackStack
192
202
  #
193
203
  balance = BlackStack::Balance.new(self.client.id, self.product_code, registraton_time)
194
204
  balance.calculate(false)
205
+ #puts "balance.credits.to_s:#{balance.credits.to_s}:."
206
+ #puts "balance.amount.to_s:#{balance.amount.to_s}:."
195
207
  total_credits = 0.to_f - balance.credits.to_f
196
208
  total_amount = 0.to_f - balance.amount.to_f
197
209
  #
@@ -199,6 +211,8 @@ module BlackStack
199
211
  #
200
212
  credits_to_expire = credits - credits_consumed.to_i #- (0.to_f - self.credits.to_f)).to_i
201
213
  amount_to_expire = total_credits.to_f == 0 ? 0 : credits_to_expire.to_f * ( total_amount.to_f / total_credits.to_f )
214
+ #puts "credits_to_expire.to_s:#{credits_to_expire.to_s}:."
215
+ #puts "amount_to_expire.to_s:#{amount_to_expire.to_s}:."
202
216
  #
203
217
  exp = BlackStack::Movement.new
204
218
  exp.id = guid()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoicing_payments_processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.61
4
+ version: 1.1.62
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-11 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket