invoicing_payments_processing 1.1.58 → 1.1.63
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/balance.rb +4 -4
- data/lib/extend_client_by_invoicing_payments_processing.rb +46 -2
- data/lib/invoice.rb +1 -12
- data/lib/movement.rb +29 -6
- 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: ff9dee57e2b7e6dc8635871fe89ec8dbe98278e8
|
4
|
+
data.tar.gz: dc3a121367f28260594a13f3996adec7b0335df9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 104338f6525e2c8b45a0b120cd6e5ac2ee71573b2c95f7885c6c6da11236ed25e89d766f8528ea19f6c92d89b0ce765b5f6eeb76579e69fc5507d33d6d6b9590
|
7
|
+
data.tar.gz: 0a8d4411793c7dc01c02cd0e642487193d35eca8f22ea27985da375d5f63a1f43e866206b80ff0ea1e30c9bd25d18805c3a7c0d359aafa16fa9a75fa54a1bf66
|
data/lib/balance.rb
CHANGED
@@ -9,14 +9,14 @@ module BlackStack
|
|
9
9
|
self.calculate()
|
10
10
|
end
|
11
11
|
|
12
|
-
def calculate()
|
13
|
-
if !self.up_time.nil?
|
12
|
+
def calculate(use_stat_balance=true)
|
13
|
+
if !self.up_time.nil? || !use_stat_balance
|
14
14
|
q =
|
15
15
|
"select cast(sum(cast(amount as numeric(18,12))) as numeric(18,6)) as amount, sum(credits) as credits " +
|
16
16
|
"from movement with (nolock) " +
|
17
17
|
"where id_client='#{self.client.id}' " +
|
18
18
|
"and product_code='#{self.product_code}' " +
|
19
|
-
"and create_time
|
19
|
+
"and create_time <= '#{self.up_time.to_time.to_sql}' "
|
20
20
|
else
|
21
21
|
q =
|
22
22
|
"select cast(sum(cast(amount as numeric(18,12))) as numeric(18,6)) as amount, sum(credits) as credits " +
|
@@ -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
|
@@ -8,8 +8,52 @@ module BlackStack
|
|
8
8
|
one_to_many :customplans, :class=>:'BlackStack::CustomPlan', :key=>:id_client
|
9
9
|
one_to_many :movements, :class=>:'BlackStack::Movement', :key=>:id_client
|
10
10
|
|
11
|
+
# how many minutes ago should have updated the table stat_balance with the amount and credits of this client, for each product.
|
12
|
+
def stat_balance_delay_minutes
|
13
|
+
row = DB[
|
14
|
+
"SELECT TOP 1 m.id " +
|
15
|
+
"FROM client c WITH (NOLOCK) " +
|
16
|
+
"JOIN movement m WITH (NOLOCK INDEX(IX_movement__id_client__create_time_desc)) ON ( c.id=m.id_client AND m.create_time > ISNULL(c.last_stat_balance_update_time, '1900-01-01') ) " +
|
17
|
+
"WHERE c.id = '#{self.id}' " +
|
18
|
+
"ORDER BY m.create_time DESC "
|
19
|
+
].first
|
20
|
+
|
21
|
+
if row.nil?
|
22
|
+
return 0
|
23
|
+
else
|
24
|
+
return DB["SELECT DATEDIFF(MI, m.create_time, GETDATE()) AS n FROM movement m WITH (NOLOCK) WHERE m.id='#{row[:id]}'"].first[:n]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# update the table stat_balance with the amount and credits of this client, for each product.
|
29
|
+
def update_stat_balance(product_code=nil)
|
30
|
+
c = self
|
31
|
+
product_descriptors = BlackStack::InvoicingPaymentsProcessing::products_descriptor.clone
|
32
|
+
product_descriptors.select! { |hprod| hprod[:code] == product_code } if !product_code.nil?
|
33
|
+
product_descriptors.each { |hprod|
|
34
|
+
row = DB[
|
35
|
+
"select isnull(sum(isnull(m.credits,0)),0) as credits, isnull(sum(isnull(m.amount,0)),0) as amount " +
|
36
|
+
# "from movement m with (nolock index(IX_movement__id_client__product_code)) " +
|
37
|
+
"from movement m with (nolock) " +
|
38
|
+
"where m.id_client='#{c.id}' " +
|
39
|
+
"and m.product_code='#{hprod[:code]}' "
|
40
|
+
].first
|
41
|
+
credits = row[:credits]
|
42
|
+
amount = row[:amount]
|
43
|
+
row = DB["SELECT * FROM stat_balance WHERE id_client='#{c.id}' AND product_code='#{hprod[:code]}'"].first
|
44
|
+
if row.nil?
|
45
|
+
DB.execute("INSERT INTO stat_balance (id_client, product_code, amount, credits) VALUES ('#{c.id}', '#{hprod[:code]}', #{amount.to_s}, #{credits.to_s})")
|
46
|
+
else
|
47
|
+
DB.execute("UPDATE stat_balance SET amount=#{amount.to_s}, credits=#{credits.to_s} WHERE id_client='#{c.id}' AND product_code='#{hprod[:code]}'")
|
48
|
+
end
|
49
|
+
DB.execute("UPDATE client SET last_stat_balance_update_time=GETDATE() WHERE [id]='#{c.id}'")
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
11
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.
|
12
|
-
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
|
+
|
13
57
|
# create the consumtion
|
14
58
|
total_credits = 0.to_f - BlackStack::Balance.new(self.id, product_code).credits.to_f
|
15
59
|
total_amount = 0.to_f - BlackStack::Balance.new(self.id, product_code).amount.to_f
|
@@ -18,7 +62,7 @@ module BlackStack
|
|
18
62
|
cons = BlackStack::Movement.new
|
19
63
|
cons.id = guid()
|
20
64
|
cons.id_client = self.id
|
21
|
-
cons.create_time =
|
65
|
+
cons.create_time = dt
|
22
66
|
cons.type = BlackStack::Movement::MOVEMENT_TYPE_CANCELATION
|
23
67
|
cons.description = description.nil? ? 'Consumption' : description
|
24
68
|
cons.paypal1_amount = 0
|
data/lib/invoice.rb
CHANGED
@@ -85,18 +85,7 @@ module BlackStack
|
|
85
85
|
def allowedToAddRemoveItems?
|
86
86
|
return (self.status == STATUS_UNPAID || self.status == nil) && (self.disabled_for_add_remove_items == false || self.disabled_for_add_remove_items == nil)
|
87
87
|
end
|
88
|
-
|
89
|
-
# envia un email transaccional con informacion de facturacion, y pasos a seguir despues del pago
|
90
|
-
def notificationSubject()
|
91
|
-
"We Received Your Payment"
|
92
|
-
end
|
93
|
-
|
94
|
-
#
|
95
|
-
def notificationBody()
|
96
|
-
"<p>We received your payment for a total of $#{("%.2f" % self.total()).to_s}.</p>" +
|
97
|
-
"<p>You can find your invoice <a href='#{CS_HOME_PAGE}/member/invoice?iid=#{self.id.to_guid}'><b>here</b></a></p>"
|
98
|
-
end
|
99
|
-
|
88
|
+
|
100
89
|
#
|
101
90
|
def number()
|
102
91
|
self.id.to_guid
|
data/lib/movement.rb
CHANGED
@@ -121,7 +121,19 @@ 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
|
-
|
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
|
+
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)
|
125
137
|
# the movment must be a payment or a bonus
|
126
138
|
raise 'Movement must be either a payment or a bonus' if self.type != MOVEMENT_TYPE_ADD_PAYMENT && self.type != MOVEMENT_TYPE_ADD_BONUS
|
127
139
|
#puts
|
@@ -131,7 +143,8 @@ module BlackStack
|
|
131
143
|
self.client.movements.select { |o|
|
132
144
|
(o.type == MOVEMENT_TYPE_ADD_PAYMENT || o.type == MOVEMENT_TYPE_ADD_BONUS) &&
|
133
145
|
o.credits.to_f < 0 &&
|
134
|
-
o.product_code.upcase == self.product_code.upcase
|
146
|
+
o.product_code.upcase == self.product_code.upcase &&
|
147
|
+
o.create_time.to_time < registraton_time.to_time
|
135
148
|
}.sort_by { |o| o.create_time }.each { |o|
|
136
149
|
paid += (0.to_f - o.credits.to_f)
|
137
150
|
break if o.id.to_guid == self.id.to_guid
|
@@ -140,7 +153,8 @@ module BlackStack
|
|
140
153
|
# calculo los credito para este producto, desde el primer dia; incluyendo cosumo, expiraciones, ajustes.
|
141
154
|
consumed = self.client.movements.select { |o|
|
142
155
|
o.credits.to_f > 0 &&
|
143
|
-
o.product_code.upcase == self.product_code.upcase
|
156
|
+
o.product_code.upcase == self.product_code.upcase &&
|
157
|
+
o.create_time.to_time < registraton_time.to_time
|
144
158
|
}.inject(0) { |sum, o| sum.to_f + o.credits.to_f }.to_f
|
145
159
|
#puts "consumed:#{consumed.to_s}:."
|
146
160
|
# calculo los creditos de este movimiento que voy a cancelar
|
@@ -184,19 +198,28 @@ module BlackStack
|
|
184
198
|
|
185
199
|
# credits expiration
|
186
200
|
def expire(registraton_time=nil, desc='Expiration Because Allocation is Renewed')
|
187
|
-
|
201
|
+
#puts
|
202
|
+
#puts "registraton_time:#{registraton_time.to_s}:."
|
203
|
+
credits_consumed = self.credits_consumed(registraton_time)
|
204
|
+
#puts "credits_consumed:#{credits_consumed.to_s}:."
|
188
205
|
#
|
189
206
|
self.expiration_start_time = now()
|
190
207
|
self.expiration_tries = self.expiration_tries.to_i + 1
|
191
208
|
self.save
|
192
209
|
#
|
193
|
-
|
194
|
-
|
210
|
+
balance = BlackStack::Balance.new(self.client.id, self.product_code, registraton_time)
|
211
|
+
balance.calculate(false)
|
212
|
+
#puts "balance.credits.to_s:#{balance.credits.to_s}:."
|
213
|
+
#puts "balance.amount.to_s:#{balance.amount.to_s}:."
|
214
|
+
total_credits = 0.to_f - balance.credits.to_f
|
215
|
+
total_amount = 0.to_f - balance.amount.to_f
|
195
216
|
#
|
196
217
|
credits = 0.to_i - self.credits.to_i
|
197
218
|
#
|
198
219
|
credits_to_expire = credits - credits_consumed.to_i #- (0.to_f - self.credits.to_f)).to_i
|
199
220
|
amount_to_expire = total_credits.to_f == 0 ? 0 : credits_to_expire.to_f * ( total_amount.to_f / total_credits.to_f )
|
221
|
+
#puts "credits_to_expire.to_s:#{credits_to_expire.to_s}:."
|
222
|
+
#puts "amount_to_expire.to_s:#{amount_to_expire.to_s}:."
|
200
223
|
#
|
201
224
|
exp = BlackStack::Movement.new
|
202
225
|
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.
|
4
|
+
version: 1.1.63
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket
|