invoicing_payments_processing 1.1.14 → 1.1.20
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 +6 -2
- data/lib/extend_client_by_invoicing_payments_processing.rb +11 -2
- data/lib/invoice.rb +1 -1
- data/lib/movement.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ebbf923439f8f516edcd98efc8f51baf0560b47
|
4
|
+
data.tar.gz: fa76d9b89823901681c0488879fc0a6023c8b40c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ad3c562d56f170ce688bb4e6dd23dbfbdb8df2e89fcb3fe61fb057703778e084d5a96223a2c2aa2e6510a4208ce0d292077fadee91a5004a16a05e11d5e8519
|
7
|
+
data.tar.gz: 718322b854e9fe1ecd512a8a557940c5930c19de3968472eebcda3dea30746a3ad67286f8953c58f88bf1c5214f882a53cb7c994f7e2507ea6375fa994ad5597
|
data/lib/balance.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module BlackStack
|
2
2
|
class Balance
|
3
|
-
attr_accessor :client, :product_code, :amount, :credits
|
3
|
+
attr_accessor :client, :product_code, :amount, :credits, :up_time
|
4
4
|
|
5
|
-
def initialize(id_client, product_code)
|
5
|
+
def initialize(id_client, product_code, up_time=nil)
|
6
6
|
self.client = BlackStack::Client.where(:id => id_client).first
|
7
7
|
self.product_code = product_code
|
8
|
+
self.up_time = up_time
|
8
9
|
self.calculate()
|
9
10
|
end
|
10
11
|
|
@@ -14,6 +15,9 @@ module BlackStack
|
|
14
15
|
"from movement with (nolock index(IX_movement__id_client__product_code)) " +
|
15
16
|
"where id_client='#{self.client.id}' " +
|
16
17
|
"and product_code='#{self.product_code}' "
|
18
|
+
|
19
|
+
q += "and create_time < '#{self.up_time.to_time.to_sql}' " if !self.up_time.nil?
|
20
|
+
|
17
21
|
row = DB[q].first
|
18
22
|
self.amount = row[:amount].to_f
|
19
23
|
self.credits = row[:credits].to_f
|
@@ -68,11 +68,11 @@ module BlackStack
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# crea un registro en la tabla movment, reduciendo la cantidad de creditos con saldo importe 0, para el producto indicado en product_code.
|
71
|
-
def adjustment(product_code, adjustment_amount=0, adjustment_credits=0, description=nil, type=BlackStack::Movement::MOVEMENT_TYPE_ADJUSTMENT)
|
71
|
+
def adjustment(product_code, adjustment_amount=0, adjustment_credits=0, description=nil, type=BlackStack::Movement::MOVEMENT_TYPE_ADJUSTMENT, registraton_time=nil)
|
72
72
|
adjust = BlackStack::Movement.new
|
73
73
|
adjust.id = guid()
|
74
74
|
adjust.id_client = self.id
|
75
|
-
adjust.create_time = now()
|
75
|
+
adjust.create_time = registraton_time.nil? ? now() : registraton_time
|
76
76
|
adjust.type = type
|
77
77
|
adjust.description = description.nil? ? 'Adjustment' : description
|
78
78
|
adjust.paypal1_amount = 0
|
@@ -113,6 +113,15 @@ module BlackStack
|
|
113
113
|
end
|
114
114
|
amount_paid += 0.to_f - o.amount.to_f
|
115
115
|
credits_paid += 0.to_i - o.credits.to_i
|
116
|
+
|
117
|
+
# if there is negative credits
|
118
|
+
total_credits = credits_paid
|
119
|
+
total_amount = amount_paid
|
120
|
+
if total_credits < 0
|
121
|
+
self.adjustment(product_code, total_amount, total_credits, 'Adjustment Because Quota Has Been Exceeded.', BlackStack::Movement::MOVEMENT_TYPE_ADJUSTMENT, o.create_time)
|
122
|
+
amount_paid = 0.to_f
|
123
|
+
credits_paid = 0.to_i
|
124
|
+
end
|
116
125
|
}
|
117
126
|
end
|
118
127
|
|
data/lib/invoice.rb
CHANGED
@@ -294,7 +294,7 @@ module BlackStack
|
|
294
294
|
#
|
295
295
|
BlackStack::Movement.where(:id_invoice_item => item.id).all { |mov|
|
296
296
|
#
|
297
|
-
mov.expire if mov.expiration_on_next_payment == true
|
297
|
+
mov.expire(self.billing_period_from) if mov.expiration_on_next_payment == true
|
298
298
|
#
|
299
299
|
DB.disconnect
|
300
300
|
GC.start
|
data/lib/movement.rb
CHANGED
@@ -61,7 +61,7 @@ module BlackStack
|
|
61
61
|
end
|
62
62
|
self.id_client = item.invoice.id_client
|
63
63
|
self.id_invoice_item = id_item.nil? ? item.id : id_item
|
64
|
-
self.create_time =
|
64
|
+
self.create_time = item.invoice.billing_period_from #payment_time
|
65
65
|
self.type = type
|
66
66
|
if (type != MOVEMENT_TYPE_ADD_BONUS)
|
67
67
|
self.paypal1_amount = item.amount.to_f
|
@@ -153,15 +153,15 @@ module BlackStack
|
|
153
153
|
end
|
154
154
|
|
155
155
|
# credits expiration
|
156
|
-
def expire()
|
156
|
+
def expire(registraton_time=nil, desc='Expiration Because Allocation is Renewed')
|
157
157
|
credits_consumed = self.credits_consumed
|
158
158
|
#
|
159
159
|
self.expiration_start_time = now()
|
160
160
|
self.expiration_tries = self.expiration_tries.to_i + 1
|
161
161
|
self.save
|
162
162
|
#
|
163
|
-
total_credits = 0.to_f - BlackStack::Balance.new(self.client.id, self.product_code).credits.to_f
|
164
|
-
total_amount = 0.to_f - BlackStack::Balance.new(self.client.id, self.product_code).amount.to_f
|
163
|
+
total_credits = 0.to_f - BlackStack::Balance.new(self.client.id, self.product_code, registraton_time).credits.to_f
|
164
|
+
total_amount = 0.to_f - BlackStack::Balance.new(self.client.id, self.product_code, registraton_time).amount.to_f
|
165
165
|
#
|
166
166
|
credits = 0.to_i - self.credits.to_i
|
167
167
|
#
|
@@ -171,10 +171,10 @@ module BlackStack
|
|
171
171
|
exp = BlackStack::Movement.new
|
172
172
|
exp.id = guid()
|
173
173
|
exp.id_client = self.client.id
|
174
|
-
exp.create_time = now()
|
174
|
+
exp.create_time = registraton_time.nil? ? now() : registraton_time
|
175
175
|
exp.type = BlackStack::Movement::MOVEMENT_TYPE_EXPIRATION
|
176
176
|
exp.id_user_creator = self.id_user_creator
|
177
|
-
exp.description =
|
177
|
+
exp.description = desc
|
178
178
|
exp.paypal1_amount = 0
|
179
179
|
exp.bonus_amount = 0
|
180
180
|
exp.amount = amount_to_expire
|