invoicing_payments_processing 1.1.62 → 1.1.67
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/extend_client_by_invoicing_payments_processing.rb +25 -2
- data/lib/invoicing_payments_processing.rb +1 -1
- data/lib/movement.rb +43 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2017f7ce80ba1e39b308c00c9a771c4b310fb753
|
4
|
+
data.tar.gz: f085954e5f6fe93aee0dad9c32ff0f1ad1ca1953
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8adc9a2686330b4361a774257fad71305957d2a9e6a7a5f082f4d1ede26edaade1475bd0251230e173720e2611b23aa4730db3fe9293ab61714e5e7405532852
|
7
|
+
data.tar.gz: a72f0bb3d39581d8a99bf9a0dcb6d52428cdc021685a60d19c0e0412cd2b85092d0583d3155e6011ca21c4bd1c87e15292d94cede5f4b869fa2757a71bda7e0d
|
@@ -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
|
-
|
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
|
@@ -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
|
|
data/lib/movement.rb
CHANGED
@@ -126,30 +126,66 @@ module BlackStack
|
|
126
126
|
#
|
127
127
|
def credits_consumed(registraton_time=nil)
|
128
128
|
# le agrego 365 dias a la fecha actual, para abarcar todas las fechas ocurridas hasta hoy seguro
|
129
|
-
|
129
|
+
if registraton_time.nil?
|
130
|
+
registraton_time = (Time.now() + 365*24*60*60)
|
131
|
+
else
|
132
|
+
registraton_time = registraton_time.to_time if registraton_time.class != Time
|
133
|
+
end
|
134
|
+
# move time to the first second of the next day.
|
135
|
+
# example: '2020-11-12 15:49:43 -0300' will be converted to '2020-11-13 00:00:00 -0300'
|
136
|
+
registraton_time = (Date.strptime(registraton_time.strftime("%Y-%m-%d"), "%Y-%m-%d").to_time + 24*60*60)
|
130
137
|
# the movment must be a payment or a bonus
|
131
138
|
raise 'Movement must be either a payment or a bonus' if self.type != MOVEMENT_TYPE_ADD_PAYMENT && self.type != MOVEMENT_TYPE_ADD_BONUS
|
132
139
|
#puts
|
140
|
+
#puts "id:#{self.id.to_guid}:."
|
133
141
|
#puts "product_code:#{self.product_code}:."
|
134
142
|
# itero los pagos y bonos hechos por este mismo producto, desde el primer dia hasta este movimiento.
|
135
|
-
|
143
|
+
=begin
|
144
|
+
paid1 = 0
|
136
145
|
self.client.movements.select { |o|
|
137
146
|
(o.type == MOVEMENT_TYPE_ADD_PAYMENT || o.type == MOVEMENT_TYPE_ADD_BONUS) &&
|
138
147
|
o.credits.to_f < 0 &&
|
139
148
|
o.product_code.upcase == self.product_code.upcase &&
|
140
|
-
o.create_time.to_time
|
149
|
+
o.create_time.to_time < registraton_time.to_time
|
141
150
|
}.sort_by { |o| o.create_time }.each { |o|
|
142
|
-
|
151
|
+
paid1 += (0.to_f - o.credits.to_f)
|
143
152
|
break if o.id.to_guid == self.id.to_guid
|
144
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}:."
|
145
167
|
#puts "paid:#{paid.to_s}:."
|
168
|
+
=begin
|
146
169
|
# calculo los credito para este producto, desde el primer dia; incluyendo cosumo, expiraciones, ajustes.
|
147
|
-
|
170
|
+
consumed1 = self.client.movements.select { |o|
|
148
171
|
o.credits.to_f > 0 &&
|
149
172
|
o.product_code.upcase == self.product_code.upcase &&
|
150
|
-
o.create_time.to_time
|
173
|
+
o.create_time.to_time < registraton_time.to_time
|
151
174
|
}.inject(0) { |sum, o| sum.to_f + o.credits.to_f }.to_f
|
152
|
-
#puts "
|
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
|
+
|
153
189
|
# calculo los creditos de este movimiento que voy a cancelar
|
154
190
|
credits = 0.to_f - self.credits.to_f
|
155
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.
|
4
|
+
version: 1.1.67
|
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
|
+
date: 2020-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket
|