invoicing_payments_processing 1.1.18 → 1.1.30
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 +1 -1
- data/lib/bufferpaypalnotification.rb +7 -16
- data/lib/extend_client_by_invoicing_payments_processing.rb +58 -6
- data/lib/invoice.rb +81 -48
- data/lib/invoiceitem.rb +10 -0
- data/lib/movement.rb +2 -2
- data/lib/paypalsubscription.rb +1 -1
- 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: 212a2966346ed12f4de648a737a3ddeaea9b4886
|
4
|
+
data.tar.gz: 891852dc15b535c8eff5bfbdcc1f5b79b3f209b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1630c612e2036f822aa5d8540a86a9279f337b93fee1419899cd56c119d165474b765b9c75a52eee8b4b3d94ba4a5e8d1c61ba7c0a7ad9eac02b14d058604781
|
7
|
+
data.tar.gz: 9e26f1b23afa365b8a09aea64d166affab51e9d15cf9e3228fa121072c3869c18a6ac75d9714e5e10c74280cd4cc18b5a106767769393282ef5e1ae6ee94c781
|
data/lib/balance.rb
CHANGED
@@ -16,7 +16,7 @@ module BlackStack
|
|
16
16
|
"where id_client='#{self.client.id}' " +
|
17
17
|
"and product_code='#{self.product_code}' "
|
18
18
|
|
19
|
-
q += "and create_time < '#{self.up_time.to_sql}' " if !self.up_time.nil?
|
19
|
+
q += "and create_time < '#{self.up_time.to_time.to_sql}' " if !self.up_time.nil?
|
20
20
|
|
21
21
|
row = DB[q].first
|
22
22
|
self.amount = row[:amount].to_f
|
@@ -331,6 +331,12 @@ module BlackStack
|
|
331
331
|
s.id_client = c.id
|
332
332
|
s.active = true
|
333
333
|
s.save
|
334
|
+
|
335
|
+
# obtengo la factura que se creo con esta suscripcion
|
336
|
+
i = BlackStack::Invoice.where(:id=>b.item_number).first
|
337
|
+
|
338
|
+
# vinculo esta suscripcion a la factura que la genero, y a todas las facturas siguientes
|
339
|
+
i.set_subscription(s)
|
334
340
|
end
|
335
341
|
|
336
342
|
elsif (
|
@@ -384,22 +390,7 @@ module BlackStack
|
|
384
390
|
k = BlackStack::Invoice.where(:id=>row[:id]).first
|
385
391
|
|
386
392
|
# creo la factura por el reembolso
|
387
|
-
|
388
|
-
i.id = guid()
|
389
|
-
i.id_client = c.id
|
390
|
-
i.create_time = now()
|
391
|
-
i.disabled_for_trial_ssm = c.disabled_for_trial_ssm
|
392
|
-
i.id_buffer_paypal_notification = b.id
|
393
|
-
i.status = BlackStack::Invoice::STATUS_REFUNDED
|
394
|
-
i.billing_period_from = b.create_time
|
395
|
-
i.billing_period_to = b.create_time
|
396
|
-
i.paypal_url = nil
|
397
|
-
i.disabled_for_add_remove_items = true
|
398
|
-
i.save()
|
399
|
-
|
400
|
-
# parseo el reeembolso - creo el registro contable
|
401
|
-
i.setup_refund(payment_gross, k.id)
|
402
|
-
|
393
|
+
k.refund(payment_gross)
|
403
394
|
end
|
404
395
|
else
|
405
396
|
# unknown
|
@@ -162,13 +162,65 @@ module BlackStack
|
|
162
162
|
if from_time > to_time
|
163
163
|
raise "From time must be earlier than To time"
|
164
164
|
end
|
165
|
-
if to_time.prev_year > from_time
|
166
|
-
|
167
|
-
end
|
165
|
+
#if to_time.prev_year > from_time
|
166
|
+
# raise "The time frame cannot be longer than 1 year."
|
167
|
+
#end
|
168
168
|
to_time += 1
|
169
|
-
|
170
|
-
|
171
|
-
|
169
|
+
=begin
|
170
|
+
:id => movement.id,
|
171
|
+
:id_client => movement.id_client,
|
172
|
+
:product_code => movement.product_code,
|
173
|
+
:create_time => movement.create_time,
|
174
|
+
:type => movement.type.to_i,
|
175
|
+
:description => movement.description,
|
176
|
+
:paypal1_amount => movement.paypal1_amount.to_f,
|
177
|
+
:bonus_amount => movement.bonus_amount.to_f,
|
178
|
+
:amount => movement.amount.to_f,
|
179
|
+
:credits => movement.credits.to_f,
|
180
|
+
:profits_amount => movement.profits_amount.to_f,
|
181
|
+
:expiration_time => movement.expiration_time,
|
182
|
+
:expiration_description => movement.expiration_time.nil? ? '-' : ((movement.expiration_time - Time.now()).to_f / 60.to_f).to_i.to_time_spent
|
183
|
+
=end
|
184
|
+
q =
|
185
|
+
"SELECT " +
|
186
|
+
" m.id_client, " +
|
187
|
+
" YEAR(m.create_time) AS creation_year, " +
|
188
|
+
" MONTH(m.create_time) AS creation_month, " +
|
189
|
+
" DAY(m.create_time) AS creation_day, " +
|
190
|
+
" YEAR(m.expiration_time) AS expiration_year, " +
|
191
|
+
" MONTH(m.expiration_time) AS expiration_month, " +
|
192
|
+
" DAY(m.expiration_time) AS expiration_day, " +
|
193
|
+
" m.type, " +
|
194
|
+
" m.product_code, " +
|
195
|
+
" CAST(m.description AS VARCHAR(500)) AS description, " +
|
196
|
+
" CAST(m.expiration_description AS VARCHAR(500)) AS expiration_description, " +
|
197
|
+
" SUM(ISNULL(m.paypal1_amount,0)) AS paypal1_amount, " +
|
198
|
+
" SUM(ISNULL(m.bonus_amount,0)) AS bonus_amount, " +
|
199
|
+
" SUM(ISNULL(m.amount,0)) AS amount, " +
|
200
|
+
" SUM(ISNULL(m.credits,0)) AS credits, " +
|
201
|
+
" SUM(ISNULL(m.profits_amount,0)) AS profits_amount " +
|
202
|
+
"FROM movement m WITH (NOLOCK) " +
|
203
|
+
"WHERE m.id_client = '#{self.id}' "
|
204
|
+
|
205
|
+
q += "AND m.product_code = '#{product_code}' " if !product_code.nil?
|
206
|
+
|
207
|
+
q +=
|
208
|
+
"AND create_time >= '#{from_time.to_sql}' " +
|
209
|
+
"AND create_time <= '#{to_time.to_sql}' " +
|
210
|
+
"GROUP BY " +
|
211
|
+
" m.id_client, " +
|
212
|
+
" YEAR(m.create_time), " +
|
213
|
+
" MONTH(m.create_time), " +
|
214
|
+
" DAY(m.create_time), " +
|
215
|
+
" YEAR(m.expiration_time), " +
|
216
|
+
" MONTH(m.expiration_time), " +
|
217
|
+
" DAY(m.expiration_time), " +
|
218
|
+
" m.type, " +
|
219
|
+
" m.product_code, " +
|
220
|
+
" CAST(m.description AS VARCHAR(500)), " +
|
221
|
+
" CAST(m.expiration_description AS VARCHAR(500)) "
|
222
|
+
|
223
|
+
DB[q].all
|
172
224
|
end
|
173
225
|
|
174
226
|
#
|
data/lib/invoice.rb
CHANGED
@@ -56,7 +56,19 @@ module BlackStack
|
|
56
56
|
raise "Unknown Invoice Status (#{status.to_s})"
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
|
+
#
|
61
|
+
def set_subscription(s)
|
62
|
+
self.subscr_id = s.subscr_id
|
63
|
+
self.save
|
64
|
+
# aplico la mismam modificacion a todas las factuas que le siguieron a esta
|
65
|
+
BlackStack::Invoice.where(:id_previous_invoice=>self.id).all { |j|
|
66
|
+
j.set_subscription(s)
|
67
|
+
DB.disconnect
|
68
|
+
GC.start
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
60
72
|
#
|
61
73
|
def deserve_trial?
|
62
74
|
return self.disabled_for_trial_ssm == false || self.disabled_for_trial_ssm == nil
|
@@ -234,6 +246,11 @@ module BlackStack
|
|
234
246
|
def canBePaid?
|
235
247
|
self.status == nil || self.status == BlackStack::Invoice::STATUS_UNPAID
|
236
248
|
end
|
249
|
+
|
250
|
+
# retorna true si el estado de la factura sea NULL o UNPAID
|
251
|
+
def canBeDeleted?
|
252
|
+
self.status == nil || self.status == BlackStack::Invoice::STATUS_UNPAID
|
253
|
+
end
|
237
254
|
|
238
255
|
# actualiza el registro en la tabla invoice segun los parametros.
|
239
256
|
# en este caso la factura se genera antes del pago.
|
@@ -286,6 +303,7 @@ module BlackStack
|
|
286
303
|
end
|
287
304
|
# marco la factura como pagada
|
288
305
|
self.status = BlackStack::Invoice::STATUS_PAID
|
306
|
+
self.delete_time = nil
|
289
307
|
self.save
|
290
308
|
# expiracion de creditos de la factura anterior
|
291
309
|
i = self.previous
|
@@ -313,19 +331,21 @@ module BlackStack
|
|
313
331
|
# registro el pago
|
314
332
|
BlackStack::Movement.new().parse(item, BlackStack::Movement::MOVEMENT_TYPE_ADD_PAYMENT, "Invoice Payment", payment_time, item.id).save()
|
315
333
|
# agrego los bonos de este plan
|
316
|
-
plan[:bonus_plans].
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
334
|
+
if !plan[:bonus_plans].nil?
|
335
|
+
plan[:bonus_plans].each { |h|
|
336
|
+
plan_bonus = BlackStack::InvoicingPaymentsProcessing.plan_descriptor(h[:item_number])
|
337
|
+
raise "bonus plan not found" if plan_bonus.nil?
|
338
|
+
bonus = BlackStack::InvoiceItem.new
|
339
|
+
bonus.id = guid()
|
340
|
+
bonus.id_invoice = self.id
|
341
|
+
bonus.product_code = plan_bonus[:product_code]
|
342
|
+
bonus.unit_price = 0
|
343
|
+
bonus.units = plan_bonus[:credits] * item.number_of_packages # agrego los creditos del bono, multiplicado por la cantiad de paquetes
|
344
|
+
bonus.amount = 0
|
345
|
+
bonus.item_number = plan_bonus[:item_number]
|
346
|
+
BlackStack::Movement.new().parse(bonus, BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS, 'Payment Bonus', payment_time, item.id).save()
|
347
|
+
}
|
348
|
+
end # if !plan[:bonus_plans].nil?
|
329
349
|
#
|
330
350
|
DB.disconnect
|
331
351
|
GC.start
|
@@ -371,62 +391,52 @@ module BlackStack
|
|
371
391
|
end
|
372
392
|
end
|
373
393
|
end
|
374
|
-
|
394
|
+
|
375
395
|
# configura la factura, segun el importe que pagara el cliente, la configuracion del plan en el descriptor h, y si el clietne merece un trial o no
|
376
|
-
def create_item(item_number, n=1, validate_items_compatibility=true)
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
# busco el primer item de esta factura, si es que existe
|
381
|
-
item0 = self.items.sort_by {|obj| obj.create_time}.first
|
382
|
-
|
383
|
-
# numero de facturas previas a esta factura
|
384
|
-
subs = BlackStack::PayPalSubscription.where(:subscr_id=>self.subscr_id).first
|
385
|
-
nSubscriptionInvoices = 0 if subs.nil?
|
386
|
-
nSubscriptionInvoices = subs.invoices.count if !subs.nil?
|
387
|
-
|
396
|
+
def create_item(item_number, n=1, validate_items_compatibility=true)
|
397
|
+
prev1 = self.previous
|
398
|
+
prev2 = prev1.nil? ? nil : prev1.previous
|
399
|
+
|
388
400
|
# encuentro el descriptor del plan
|
389
401
|
# el descriptor del plan tambien es necesario para la llamada a paypal_link
|
390
402
|
h = self.client.plans.select { |j| j[:item_number].to_s == item_number.to_s }.first
|
391
403
|
|
392
404
|
# mapeo variables
|
393
|
-
c = self.client
|
394
405
|
amount = 0.to_f
|
395
406
|
unit_price = 0.to_f
|
396
407
|
units = 0.to_i
|
397
|
-
|
398
|
-
# decido si se trata de una suscripcion
|
399
|
-
isSubscription = false
|
400
|
-
isSubscription = true if h[:type] == "S"
|
401
|
-
|
408
|
+
|
402
409
|
# le seteo la fecha de hoy
|
403
410
|
self.billing_period_from = now()
|
404
|
-
|
405
|
-
|
411
|
+
#puts
|
412
|
+
#puts
|
406
413
|
# si el plan tiene un primer trial, y
|
407
|
-
# es primer
|
408
|
-
# => se trata del primer pago por trial
|
409
|
-
if
|
414
|
+
# es la primer factura, entonces:
|
415
|
+
# => se trata del primer pago por trial
|
416
|
+
if h[:trial_fee] != nil && prev1.nil? && !self.disabled_for_trial_ssm
|
417
|
+
#puts 'a'
|
410
418
|
units = h[:trial_credits].to_i
|
411
419
|
unit_price = h[:trial_fee].to_f / h[:trial_credits].to_f
|
412
420
|
billing_period_to = DB["SELECT DATEADD(#{h[:trial_period].to_s}, +#{h[:trial_units].to_s}, '#{self.billing_period_from.to_s}') AS [now]"].map(:now)[0].to_s
|
413
421
|
|
414
|
-
# si es una suscripcion, y
|
415
422
|
# si el plan tiene un segundo trial, y
|
416
|
-
# es
|
417
|
-
# => se trata del segundo pago por trial
|
418
|
-
elsif
|
423
|
+
# es la segunda factura, entonces:
|
424
|
+
# => se trata del segundo pago por segundo trial
|
425
|
+
elsif h[:trial2_fee] != nil && !prev1.nil? && prev2.nil?
|
426
|
+
#puts 'b'
|
419
427
|
units = h[:trial2_credits].to_i
|
420
428
|
unit_price = h[:trial2_fee].to_f / h[:trial2_credits].to_f
|
421
429
|
billing_period_to = DB["SELECT DATEADD(#{h[:trial2_period].to_s}, +#{h[:trial2_units].to_s}, '#{self.billing_period_from.to_s}') AS [now]"].map(:now)[0].to_s
|
422
430
|
|
423
431
|
# si el plan tiene un fee, y
|
424
|
-
elsif
|
432
|
+
elsif h[:fee].to_f != nil && h[:type] == BlackStack::InvoicingPaymentsProcessing::BasePlan::PAYMENT_SUBSCRIPTION
|
433
|
+
#puts 'c'
|
425
434
|
units = n.to_i * h[:credits].to_i
|
426
435
|
unit_price = h[:fee].to_f / h[:credits].to_f
|
427
436
|
billing_period_to = DB["SELECT DATEADD(#{h[:period].to_s}, +#{h[:units].to_s}, '#{self.billing_period_from.to_s}') AS [now]"].map(:now)[0].to_s
|
428
437
|
|
429
|
-
elsif
|
438
|
+
elsif h[:fee].to_f != nil && h[:type] == BlackStack::InvoicingPaymentsProcessing::BasePlan::PAYMENT_PAY_AS_YOU_GO
|
439
|
+
#puts 'd'
|
430
440
|
units = n.to_i * h[:credits].to_i
|
431
441
|
unit_price = h[:fee].to_f / h[:credits].to_f
|
432
442
|
billing_period_to = billing_period_from
|
@@ -435,7 +445,8 @@ module BlackStack
|
|
435
445
|
raise "Plan is specified wrong"
|
436
446
|
|
437
447
|
end
|
438
|
-
|
448
|
+
|
449
|
+
|
439
450
|
#
|
440
451
|
amount = units.to_f * unit_price.to_f
|
441
452
|
|
@@ -521,9 +532,9 @@ module BlackStack
|
|
521
532
|
self.id_previous_invoice = i.id
|
522
533
|
self.subscr_id = i.subscr_id
|
523
534
|
self.disabled_for_add_remove_items = true
|
524
|
-
|
535
|
+
|
525
536
|
i.items.each { |t|
|
526
|
-
self.add_item(t.item_number)
|
537
|
+
self.add_item(t.item_number, t.number_of_packages)
|
527
538
|
#
|
528
539
|
DB.disconnect
|
529
540
|
GC.start
|
@@ -657,6 +668,28 @@ module BlackStack
|
|
657
668
|
DB.disconnect
|
658
669
|
GC.start
|
659
670
|
end # def setup_refund
|
660
|
-
|
671
|
+
|
672
|
+
def refund(amount)
|
673
|
+
c = self.client
|
674
|
+
# creo la factura por el reembolso
|
675
|
+
j = BlackStack::Invoice.new()
|
676
|
+
j.id = guid()
|
677
|
+
j.id_client = c.id
|
678
|
+
j.create_time = now()
|
679
|
+
j.disabled_for_trial_ssm = c.disabled_for_trial_ssm
|
680
|
+
j.id_buffer_paypal_notification = nil
|
681
|
+
j.status = BlackStack::Invoice::STATUS_REFUNDED
|
682
|
+
j.billing_period_from = self.billing_period_from
|
683
|
+
j.billing_period_to = self.billing_period_to
|
684
|
+
j.paypal_url = nil
|
685
|
+
j.disabled_for_add_remove_items = true
|
686
|
+
j.subscr_id = self.subscr_id
|
687
|
+
j.id_previous_invoice = self.id
|
688
|
+
j.save()
|
689
|
+
|
690
|
+
# parseo el reeembolso - creo el registro contable
|
691
|
+
j.setup_refund(amount, self.id)
|
692
|
+
end # refund
|
693
|
+
|
661
694
|
end # class Invoice
|
662
695
|
end # module BlackStack
|
data/lib/invoiceitem.rb
CHANGED
@@ -7,5 +7,15 @@ module BlackStack
|
|
7
7
|
BlackStack::InvoicingPaymentsProcessing::plan_descriptor(self.item_number)
|
8
8
|
end
|
9
9
|
|
10
|
+
# Returns the number of plans ordered in this item
|
11
|
+
def number_of_packages()
|
12
|
+
plan = BlackStack::InvoicingPaymentsProcessing.plan_descriptor(self.item_number)
|
13
|
+
if self.amount.to_f == plan[:trial_fee].to_f || self.amount.to_f == plan[:trial2_fee].to_f
|
14
|
+
return 1.to_i
|
15
|
+
else
|
16
|
+
return (self.units.to_f / plan[:credits].to_f).to_i
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
10
20
|
end # class LocalInvoiceItem
|
11
21
|
end # module BlackStack
|
data/lib/movement.rb
CHANGED
@@ -153,7 +153,7 @@ module BlackStack
|
|
153
153
|
end
|
154
154
|
|
155
155
|
# credits expiration
|
156
|
-
def expire(registraton_time=nil)
|
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()
|
@@ -174,7 +174,7 @@ module BlackStack
|
|
174
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
|
data/lib/paypalsubscription.rb
CHANGED
@@ -116,7 +116,7 @@ module BlackStack
|
|
116
116
|
DB[
|
117
117
|
"SELECT DISTINCT i.id " +
|
118
118
|
"FROM invoice i WITH (NOLOCK) " +
|
119
|
-
"
|
119
|
+
"WHERE i.subscr_id='#{self.subscr_id.to_s}' "
|
120
120
|
].all { |row|
|
121
121
|
a << BlackStack::Invoice.where(:id=>row[:id]).first
|
122
122
|
# release resources
|
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.30
|
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
|
+
date: 2020-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket
|