invoicing_payments_processing 1.1.19 → 1.1.31

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: 15ea3cb7bab52cf67e153c4f59323b469a86dcea
4
- data.tar.gz: 20b39e8d38a01f61328c69a09caedc3d44f0afbd
3
+ metadata.gz: 91c8cdb3f2b07357df4ed4d7e53b42f3d13ccce9
4
+ data.tar.gz: 60242afcacd6a836b87324255b0a39af9cad79e7
5
5
  SHA512:
6
- metadata.gz: 24da2b5af19f31b4a6cc4271fa2d6ecc48c3ec2779dd9e00bf5d70850f2663a9340062102e6cb41d0d95fecc8a1aedca05dd61e7985054ad8b8f3e35a6a2e168
7
- data.tar.gz: ce9b2d4b2e5b721019dd90a3e58c6296a9c9b9ce431525a46b7be9601853fa281bc8cb7c2ce0b976ecc0e942cd59f8482517433ca8beedf453729c3c9c61bb83
6
+ metadata.gz: 9c0951c13e1665cb9c5b5e16a5fa1024667fcd2178701d7c9f8ab8ab620a95837b45f5a8375c283eeb36dff9f240159deac6a5864d0be3ab75f6fbae0f2d4133
7
+ data.tar.gz: 6cb8ab4e9a8332c7d934a3629e673a0869a62076a03dc2177987e1eec1e515a56f981b1cfdac44e33efc5c50c98f4b5b8fb67dd868dd2057f4e1c6e83e331503
@@ -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
- i = BlackStack::Invoice.new()
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
- raise "There time frame cannot be longer than 1 year."
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
- ds = BlackStack::Movement.where(:id_client => self.id, :product_code=>product_code) if !product_code.nil?
170
- ds = BlackStack::Movement.where(:id_client => self.id) if product_code.nil?
171
- ds.where("create_time >= ? and create_time <= ?", from_time, to_time)
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
  #
@@ -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,15 @@ 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
+ if self.paypal_subscription.nil?
253
+ return self.status == nil || self.status == BlackStack::Invoice::STATUS_UNPAID
254
+ else # !self.paypal_subscription.nil?
255
+ return (self.status == nil || self.status == BlackStack::Invoice::STATUS_UNPAID) && !self.paypal_subscription.active
256
+ end # if self.paypal_subscription.nil?
257
+ end
237
258
 
238
259
  # actualiza el registro en la tabla invoice segun los parametros.
239
260
  # en este caso la factura se genera antes del pago.
@@ -286,6 +307,7 @@ module BlackStack
286
307
  end
287
308
  # marco la factura como pagada
288
309
  self.status = BlackStack::Invoice::STATUS_PAID
310
+ self.delete_time = nil
289
311
  self.save
290
312
  # expiracion de creditos de la factura anterior
291
313
  i = self.previous
@@ -313,19 +335,21 @@ module BlackStack
313
335
  # registro el pago
314
336
  BlackStack::Movement.new().parse(item, BlackStack::Movement::MOVEMENT_TYPE_ADD_PAYMENT, "Invoice Payment", payment_time, item.id).save()
315
337
  # agrego los bonos de este plan
316
- plan[:bonus_plans].each { |h|
317
- plan_bonus = BlackStack::InvoicingPaymentsProcessing.plan_descriptor(h[:item_number])
318
- raise "bonus plan not found" if plan_bonus.nil?
319
- bonus = BlackStack::InvoiceItem.new
320
- bonus.id = guid()
321
- bonus.id_invoice = self.id
322
- bonus.product_code = plan_bonus[:product_code]
323
- bonus.unit_price = 0
324
- bonus.units = plan_bonus[:credits]
325
- bonus.amount = 0
326
- bonus.item_number = plan_bonus[:item_number]
327
- BlackStack::Movement.new().parse(bonus, BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS, 'Payment Bonus', payment_time, item.id).save()
328
- }
338
+ if !plan[:bonus_plans].nil?
339
+ plan[:bonus_plans].each { |h|
340
+ plan_bonus = BlackStack::InvoicingPaymentsProcessing.plan_descriptor(h[:item_number])
341
+ raise "bonus plan not found" if plan_bonus.nil?
342
+ bonus = BlackStack::InvoiceItem.new
343
+ bonus.id = guid()
344
+ bonus.id_invoice = self.id
345
+ bonus.product_code = plan_bonus[:product_code]
346
+ bonus.unit_price = 0
347
+ bonus.units = plan_bonus[:credits] * item.number_of_packages # agrego los creditos del bono, multiplicado por la cantiad de paquetes
348
+ bonus.amount = 0
349
+ bonus.item_number = plan_bonus[:item_number]
350
+ BlackStack::Movement.new().parse(bonus, BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS, 'Payment Bonus', payment_time, item.id).save()
351
+ }
352
+ end # if !plan[:bonus_plans].nil?
329
353
  #
330
354
  DB.disconnect
331
355
  GC.start
@@ -371,62 +395,52 @@ module BlackStack
371
395
  end
372
396
  end
373
397
  end
374
-
398
+
375
399
  # 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
- deserve_trial = self.deserve_trial?
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
-
400
+ def create_item(item_number, n=1, validate_items_compatibility=true)
401
+ prev1 = self.previous
402
+ prev2 = prev1.nil? ? nil : prev1.previous
403
+
388
404
  # encuentro el descriptor del plan
389
405
  # el descriptor del plan tambien es necesario para la llamada a paypal_link
390
406
  h = self.client.plans.select { |j| j[:item_number].to_s == item_number.to_s }.first
391
407
 
392
408
  # mapeo variables
393
- c = self.client
394
409
  amount = 0.to_f
395
410
  unit_price = 0.to_f
396
411
  units = 0.to_i
397
-
398
- # decido si se trata de una suscripcion
399
- isSubscription = false
400
- isSubscription = true if h[:type] == "S"
401
-
412
+
402
413
  # le seteo la fecha de hoy
403
414
  self.billing_period_from = now()
404
-
405
- # si es una suscripcion, y
415
+ #puts
416
+ #puts
406
417
  # si el plan tiene un primer trial, y
407
- # es primer pago de esta suscripcion, entonces:
408
- # => se trata del primer pago por trial de esta suscripcion
409
- if (isSubscription && h[:trial_fee] != nil && deserve_trial)
418
+ # es la primer factura, entonces:
419
+ # => se trata del primer pago por trial
420
+ if h[:trial_fee] != nil && prev1.nil? && !self.disabled_for_trial_ssm
421
+ #puts 'a'
410
422
  units = h[:trial_credits].to_i
411
423
  unit_price = h[:trial_fee].to_f / h[:trial_credits].to_f
412
424
  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
425
 
414
- # si es una suscripcion, y
415
426
  # si el plan tiene un segundo trial, y
416
- # es segundo pago de esta suscripcion, entonces:
417
- # => se trata del segundo pago por trial de esta suscripcion
418
- elsif (isSubscription && h[:trial2_fee] != nil && nSubscriptionInvoices == 1)
427
+ # es la segunda factura, entonces:
428
+ # => se trata del segundo pago por segundo trial
429
+ elsif h[:trial2_fee] != nil && !prev1.nil? && prev2.nil?
430
+ #puts 'b'
419
431
  units = h[:trial2_credits].to_i
420
432
  unit_price = h[:trial2_fee].to_f / h[:trial2_credits].to_f
421
433
  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
434
 
423
435
  # si el plan tiene un fee, y
424
- elsif (isSubscription && h[:fee].to_f != nil)
436
+ elsif h[:fee].to_f != nil && h[:type] == BlackStack::InvoicingPaymentsProcessing::BasePlan::PAYMENT_SUBSCRIPTION
437
+ #puts 'c'
425
438
  units = n.to_i * h[:credits].to_i
426
439
  unit_price = h[:fee].to_f / h[:credits].to_f
427
440
  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
441
 
429
- elsif (!isSubscription && h[:fee].to_f != nil)
442
+ elsif h[:fee].to_f != nil && h[:type] == BlackStack::InvoicingPaymentsProcessing::BasePlan::PAYMENT_PAY_AS_YOU_GO
443
+ #puts 'd'
430
444
  units = n.to_i * h[:credits].to_i
431
445
  unit_price = h[:fee].to_f / h[:credits].to_f
432
446
  billing_period_to = billing_period_from
@@ -435,7 +449,8 @@ module BlackStack
435
449
  raise "Plan is specified wrong"
436
450
 
437
451
  end
438
-
452
+
453
+
439
454
  #
440
455
  amount = units.to_f * unit_price.to_f
441
456
 
@@ -521,9 +536,9 @@ module BlackStack
521
536
  self.id_previous_invoice = i.id
522
537
  self.subscr_id = i.subscr_id
523
538
  self.disabled_for_add_remove_items = true
524
-
539
+
525
540
  i.items.each { |t|
526
- self.add_item(t.item_number)
541
+ self.add_item(t.item_number, t.number_of_packages)
527
542
  #
528
543
  DB.disconnect
529
544
  GC.start
@@ -657,6 +672,28 @@ module BlackStack
657
672
  DB.disconnect
658
673
  GC.start
659
674
  end # def setup_refund
660
-
675
+
676
+ def refund(amount)
677
+ c = self.client
678
+ # creo la factura por el reembolso
679
+ j = BlackStack::Invoice.new()
680
+ j.id = guid()
681
+ j.id_client = c.id
682
+ j.create_time = now()
683
+ j.disabled_for_trial_ssm = c.disabled_for_trial_ssm
684
+ j.id_buffer_paypal_notification = nil
685
+ j.status = BlackStack::Invoice::STATUS_REFUNDED
686
+ j.billing_period_from = self.billing_period_from
687
+ j.billing_period_to = self.billing_period_to
688
+ j.paypal_url = nil
689
+ j.disabled_for_add_remove_items = true
690
+ j.subscr_id = self.subscr_id
691
+ j.id_previous_invoice = self.id
692
+ j.save()
693
+
694
+ # parseo el reeembolso - creo el registro contable
695
+ j.setup_refund(amount, self.id)
696
+ end # refund
697
+
661
698
  end # class Invoice
662
699
  end # module BlackStack
@@ -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
@@ -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 = 'Expiration Because Allocation is Renewed'
177
+ exp.description = desc
178
178
  exp.paypal1_amount = 0
179
179
  exp.bonus_amount = 0
180
180
  exp.amount = amount_to_expire
@@ -116,7 +116,7 @@ module BlackStack
116
116
  DB[
117
117
  "SELECT DISTINCT i.id " +
118
118
  "FROM invoice i WITH (NOLOCK) " +
119
- "JOIN buffer_paypal_notification b WITH (NOLOCK) ON (b.id=i.id_buffer_paypal_notification AND b.subscr_id='#{self.subscr_id.to_s}') "
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.19
4
+ version: 1.1.31
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-08-01 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket