invoicing_payments_processing 1.1.63 → 1.1.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff9dee57e2b7e6dc8635871fe89ec8dbe98278e8
4
- data.tar.gz: dc3a121367f28260594a13f3996adec7b0335df9
3
+ metadata.gz: 36b5fd6212a599f4855cbfce22cf021275bef49c
4
+ data.tar.gz: 98bf47011621c2518e1f377a80cadfbb3114d786
5
5
  SHA512:
6
- metadata.gz: 104338f6525e2c8b45a0b120cd6e5ac2ee71573b2c95f7885c6c6da11236ed25e89d766f8528ea19f6c92d89b0ce765b5f6eeb76579e69fc5507d33d6d6b9590
7
- data.tar.gz: 0a8d4411793c7dc01c02cd0e642487193d35eca8f22ea27985da375d5f63a1f43e866206b80ff0ea1e30c9bd25d18805c3a7c0d359aafa16fa9a75fa54a1bf66
6
+ metadata.gz: ff41e764185ebcc320595801cbddf48aecc34fc28dc48b8f82bdceb4660d63a74d88b25c51b53c93895685397dd38524fa023443fe040bcfab4300019ffb31b7
7
+ data.tar.gz: e6f2aa52eeb41fdd00f9f4b1635d81d73d5982f737312868615c1a076ac5a3dbf5b09da0658e2e0e92febf0fc7d6424fc90214e82f764d5efb7e7f9faf5d8fc5
@@ -6,7 +6,30 @@ module BlackStack
6
6
  class Client < Sequel::Model(:client)
7
7
  one_to_many :paypal_subscriptions, :class=>:'BlackStack::PayPalSubscription', :key=>:id_client
8
8
  one_to_many :customplans, :class=>:'BlackStack::CustomPlan', :key=>:id_client
9
- one_to_many :movements, :class=>:'BlackStack::Movement', :key=>:id_client
9
+
10
+ # This method replace the line:
11
+ # one_to_many :movements, :class=>:'BlackStack::Movement', :key=>:id_client
12
+ #
13
+ # Because when you have a large number of records in the table movement, for a client,
14
+ # then the call to this attribute client.movements can take too much time and generates
15
+ # a query timeout exception.
16
+ #
17
+ # The call to this method may take too much time, but ti won't raise a query timeout.
18
+ #
19
+ def movements
20
+ i = 0
21
+ ret = []
22
+ BlackStack::Movement.where(:id_client=>self.id).each { |o|
23
+ ret << o
24
+ i += 1
25
+ if i == 1000
26
+ i = 0
27
+ GC.start
28
+ DB.disconnect
29
+ end
30
+ }
31
+ ret
32
+ end
10
33
 
11
34
  # how many minutes ago should have updated the table stat_balance with the amount and credits of this client, for each product.
12
35
  def stat_balance_delay_minutes
@@ -137,7 +160,7 @@ module BlackStack
137
160
  credits_paid = 0
138
161
 
139
162
  #total_credits = 0.to_f - BlackStack::Balance.new(self.id, product_code).credits.to_f
140
- #total_amount = 0.to_f - BlackStack::Balance.new(self.id, product_code).amount.to_f
163
+ #total_amount = 0.to_f - BlackStack::Balance.new(self.id, product_code).amount.to_f
141
164
 
142
165
  self.movements.select { |o|
143
166
  o.product_code.upcase == product_code.upcase
@@ -625,29 +625,31 @@ module BlackStack
625
625
  end # if net_amount < 0
626
626
  # hago el reembolso de cada bono de este item
627
627
  # si el balance quedo en negativo, entonces aplico otro ajuste
628
- h[:bonus_plans].each { |bonus|
629
- i = BlackStack::InvoicingPaymentsProcessing::plans_descriptor.select { |obj| obj[:item_number] == bonus[:item_number] }.first
630
- j = BlackStack::InvoicingPaymentsProcessing::products_descriptor.select { |obj| obj[:code] == i[:product_code] }.first
631
- item2 = BlackStack::InvoiceItem.new()
632
- item2.id = guid()
633
- item2.id_invoice = self.id
634
- item2.unit_price = 0
635
- item2.units = -i[:credits]
636
- item2.amount = 0
637
- item2.product_code = i[:product_code].to_s
638
- item2.item_number = i[:item_number].to_s
639
- item2.detail = 'Bonus Refund'
640
- item2.description = j[:description].to_s
641
- item2.save()
642
- BlackStack::Movement.new().parse(item2, BlackStack::Movement::MOVEMENT_TYPE_REFUND_BALANCE, "Bonus Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.").save()
643
- net_amount = 0.to_f - BlackStack::Balance.new(self.client.id, i[:product_code].to_s).amount.to_f
644
- net_credits = 0.to_f - BlackStack::Balance.new(self.client.id, i[:product_code].to_s).credits.to_f
645
- if net_amount <= 0 && net_credits < 0
646
- adjust = self.client.adjustment(i[:product_code].to_s, net_amount, net_credits, "Adjustment for Negative Balance After Bonus Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.")
647
- adjust.id_invoice_item = item1.id
648
- adjust.save
649
- end # if net_amount < 0
650
- }
628
+ if !h[:bonus_plans].nil?
629
+ h[:bonus_plans].each { |bonus|
630
+ i = BlackStack::InvoicingPaymentsProcessing::plans_descriptor.select { |obj| obj[:item_number] == bonus[:item_number] }.first
631
+ j = BlackStack::InvoicingPaymentsProcessing::products_descriptor.select { |obj| obj[:code] == i[:product_code] }.first
632
+ item2 = BlackStack::InvoiceItem.new()
633
+ item2.id = guid()
634
+ item2.id_invoice = self.id
635
+ item2.unit_price = 0
636
+ item2.units = -i[:credits]
637
+ item2.amount = 0
638
+ item2.product_code = i[:product_code].to_s
639
+ item2.item_number = i[:item_number].to_s
640
+ item2.detail = 'Bonus Refund'
641
+ item2.description = j[:description].to_s
642
+ item2.save()
643
+ BlackStack::Movement.new().parse(item2, BlackStack::Movement::MOVEMENT_TYPE_REFUND_BALANCE, "Bonus Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.").save()
644
+ net_amount = 0.to_f - BlackStack::Balance.new(self.client.id, i[:product_code].to_s).amount.to_f
645
+ net_credits = 0.to_f - BlackStack::Balance.new(self.client.id, i[:product_code].to_s).credits.to_f
646
+ if net_amount <= 0 && net_credits < 0
647
+ adjust = self.client.adjustment(i[:product_code].to_s, net_amount, net_credits, "Adjustment for Negative Balance After Bonus Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.")
648
+ adjust.id_invoice_item = item1.id
649
+ adjust.save
650
+ end # if net_amount < 0
651
+ }
652
+ end # if !h[:bonus_plans].nil?
651
653
  # release resources
652
654
  DB.disconnect
653
655
  GC.start
@@ -63,7 +63,7 @@ module BlackStack
63
63
 
64
64
  def self.plan_descriptor(item_number)
65
65
  plan = BlackStack::InvoicingPaymentsProcessing::plans_descriptor.select { |h| h[:item_number].to_s == item_number.to_s }.first
66
- raise "Plan not found" if plan.nil?
66
+ raise "Plan not found (#{item_number.to_s})" if plan.nil?
67
67
  plan
68
68
  end
69
69
 
@@ -137,26 +137,55 @@ module BlackStack
137
137
  # the movment must be a payment or a bonus
138
138
  raise 'Movement must be either a payment or a bonus' if self.type != MOVEMENT_TYPE_ADD_PAYMENT && self.type != MOVEMENT_TYPE_ADD_BONUS
139
139
  #puts
140
+ #puts "id:#{self.id.to_guid}:."
140
141
  #puts "product_code:#{self.product_code}:."
141
142
  # itero los pagos y bonos hechos por este mismo producto, desde el primer dia hasta este movimiento.
142
- paid = 0
143
+ =begin
144
+ paid1 = 0
143
145
  self.client.movements.select { |o|
144
146
  (o.type == MOVEMENT_TYPE_ADD_PAYMENT || o.type == MOVEMENT_TYPE_ADD_BONUS) &&
145
147
  o.credits.to_f < 0 &&
146
148
  o.product_code.upcase == self.product_code.upcase &&
147
149
  o.create_time.to_time < registraton_time.to_time
148
150
  }.sort_by { |o| o.create_time }.each { |o|
149
- paid += (0.to_f - o.credits.to_f)
151
+ paid1 += (0.to_f - o.credits.to_f)
150
152
  break if o.id.to_guid == self.id.to_guid
151
153
  }
154
+ #puts "paid1:#{paid1.to_s}:."
155
+ =end
156
+ q =
157
+ "select ISNULL(SUM(ISNULL(m.credits,0)),0) AS n " +
158
+ "from movement m with (nolock) " +
159
+ "where isnull(m.type, #{BlackStack::Movement::MOVEMENT_TYPE_ADD_PAYMENT.to_s}) in (#{BlackStack::Movement::MOVEMENT_TYPE_ADD_PAYMENT.to_s}, #{BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS.to_s}) " +
160
+ "and m.id_client='#{self.client.id.to_guid}' " +
161
+ "and isnull(m.credits,0) < 0 " +
162
+ "and upper(isnull(m.product_code, '')) = '#{self.product_code.upcase}' " +
163
+ "and m.create_time < '#{registraton_time.to_time.strftime('%Y-%m-%d')}' " +
164
+ "and m.create_time <= (select m2.create_time from movement m2 with (nolock) where m2.id='#{self.id.to_guid}') "
165
+ paid = 0 - DB[q].first[:n]
166
+ #puts "q:#{q.to_s}:."
152
167
  #puts "paid:#{paid.to_s}:."
168
+ =begin
153
169
  # calculo los credito para este producto, desde el primer dia; incluyendo cosumo, expiraciones, ajustes.
154
- consumed = self.client.movements.select { |o|
170
+ consumed1 = self.client.movements.select { |o|
155
171
  o.credits.to_f > 0 &&
156
172
  o.product_code.upcase == self.product_code.upcase &&
157
173
  o.create_time.to_time < registraton_time.to_time
158
174
  }.inject(0) { |sum, o| sum.to_f + o.credits.to_f }.to_f
159
- #puts "consumed:#{consumed.to_s}:."
175
+ #puts "consumed1:#{consumed1.to_s}:."
176
+ =end
177
+ q =
178
+ "select ISNULL(SUM(ISNULL(m.credits,0)),0) AS n " +
179
+ "from movement m with (nolock) " +
180
+ "where m.id_client='#{self.client.id.to_guid}' " +
181
+ "and isnull(m.credits,0) > 0 " +
182
+ "and upper(isnull(m.product_code, '')) = '#{self.product_code.upcase}' " +
183
+ "and m.create_time < '#{registraton_time.to_time.strftime('%Y-%m-%d')}' " #+
184
+ # "and m.id <> '#{self.id.to_guid}' "
185
+ consumed = DB[q].first[:n]
186
+ #puts "q:#{q.to_s}:."
187
+ #puts "consumed:#{consumed.to_s}:."
188
+
160
189
  # calculo los creditos de este movimiento que voy a cancelar
161
190
  credits = 0.to_f - self.credits.to_f
162
191
  #puts "credits:#{credits.to_s}:."
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.63
4
+ version: 1.1.68
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-12 00:00:00.000000000 Z
11
+ date: 2020-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket