invoicing_payments_processing 1.1.54 → 1.1.60
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 +4 -4
- data/lib/balance.rb +16 -9
- data/lib/extend_client_by_invoicing_payments_processing.rb +42 -0
- data/lib/invoice.rb +2 -13
- data/lib/invoicing_payments_processing.rb +16 -3
- data/lib/movement.rb +4 -2
- 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: aa3e73d17b05d75e69025d7364460ee6045a46cb
|
|
4
|
+
data.tar.gz: 2579bdc5324a9288e41fa92c9f2f84048f0c27f2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e3138f3c9a4721c504eba4376923717cf50af2382204020150d10fc480c3a6e536e6c09d7d56457d999aac9bcecf4b42388f2b686d91b5eb502291a4cbfed494
|
|
7
|
+
data.tar.gz: e3ef838af52b803608c1349a3e31b682afefb846716570e7fe38ee8070f73f96aaeecbf665b7b8d8641ae405b41859d60ccd43d1624c585ed5d2f6baa50e9074
|
data/lib/balance.rb
CHANGED
|
@@ -9,15 +9,22 @@ module BlackStack
|
|
|
9
9
|
self.calculate()
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def calculate()
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
def calculate(use_stat_balance=true)
|
|
13
|
+
if !self.up_time.nil? || !use_stat_balance
|
|
14
|
+
q =
|
|
15
|
+
"select cast(sum(cast(amount as numeric(18,12))) as numeric(18,6)) as amount, sum(credits) as credits " +
|
|
16
|
+
"from movement with (nolock) " +
|
|
17
|
+
"where id_client='#{self.client.id}' " +
|
|
18
|
+
"and product_code='#{self.product_code}' " +
|
|
19
|
+
"and create_time < '#{self.up_time.to_time.to_sql}' "
|
|
20
|
+
else
|
|
21
|
+
q =
|
|
22
|
+
"select cast(sum(cast(amount as numeric(18,12))) as numeric(18,6)) as amount, sum(credits) as credits " +
|
|
23
|
+
"from stat_balance x with (nolock) " +
|
|
24
|
+
"where x.id_client='#{self.client.id}' " +
|
|
25
|
+
"and x.product_code='#{self.product_code}' "
|
|
26
|
+
end
|
|
27
|
+
|
|
21
28
|
row = DB[q].first
|
|
22
29
|
self.amount = row[:amount].to_f
|
|
23
30
|
self.credits = row[:credits].to_f
|
|
@@ -8,6 +8,48 @@ 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
54
|
def consume(product_code, number_of_credits=1, description=nil)
|
|
13
55
|
# create the consumtion
|
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
|
|
@@ -246,7 +235,7 @@ module BlackStack
|
|
|
246
235
|
end
|
|
247
236
|
|
|
248
237
|
# return url
|
|
249
|
-
"#{BlackStack::InvoicingPaymentsProcessing::
|
|
238
|
+
"#{BlackStack::InvoicingPaymentsProcessing::paypal_orders_url}/cgi-bin/webscr?" + URI.encode_www_form(values)
|
|
250
239
|
end
|
|
251
240
|
|
|
252
241
|
# retorna true si el estado de la factura sea NULL o UNPAID
|
|
@@ -13,10 +13,19 @@ module BlackStack
|
|
|
13
13
|
|
|
14
14
|
# static attributes
|
|
15
15
|
@@paypal_business_email = "sardi.leandro.daniel@gmail.com"
|
|
16
|
+
@@paypal_orders_url = BlackStack::InvoicingPaymentsProcessing::PAYPAL_ORDERS_URL
|
|
17
|
+
@@paypal_ipn_listener = "#{BlackStack::Pampa::api_url.to_s}/api1.3/accounting/paypal/notify_new_invoice.json"
|
|
18
|
+
|
|
16
19
|
@@products_descriptor = []
|
|
17
20
|
@@plans_descriptor = []
|
|
18
|
-
|
|
21
|
+
|
|
19
22
|
# getters & setters
|
|
23
|
+
def self.set_config(h)
|
|
24
|
+
@@paypal_business_email = h[:paypal_business_email]
|
|
25
|
+
@@paypal_orders_url = h[:paypal_orders_url]
|
|
26
|
+
@@paypal_ipn_listener = h[:paypal_ipn_listener]
|
|
27
|
+
end
|
|
28
|
+
|
|
20
29
|
def self.set_paypal_business_email(email)
|
|
21
30
|
@@paypal_business_email = email
|
|
22
31
|
end # def self.set_paypal_business_email
|
|
@@ -25,10 +34,14 @@ module BlackStack
|
|
|
25
34
|
@@paypal_business_email
|
|
26
35
|
end # def self.set_paypal_business_email
|
|
27
36
|
|
|
28
|
-
def self.
|
|
29
|
-
|
|
37
|
+
def self.paypal_orders_url()
|
|
38
|
+
@@paypal_orders_url
|
|
30
39
|
end
|
|
31
40
|
|
|
41
|
+
def self.paypal_ipn_listener()
|
|
42
|
+
@@paypal_ipn_listener
|
|
43
|
+
end
|
|
44
|
+
|
|
32
45
|
|
|
33
46
|
def self.set_products(h)
|
|
34
47
|
@@products_descriptor = h
|
data/lib/movement.rb
CHANGED
|
@@ -190,8 +190,10 @@ module BlackStack
|
|
|
190
190
|
self.expiration_tries = self.expiration_tries.to_i + 1
|
|
191
191
|
self.save
|
|
192
192
|
#
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
balance = BlackStack::Balance.new(self.client.id, self.product_code, registraton_time)
|
|
194
|
+
balance.calculate(false)
|
|
195
|
+
total_credits = 0.to_f - balance.credits.to_f
|
|
196
|
+
total_amount = 0.to_f - balance.amount.to_f
|
|
195
197
|
#
|
|
196
198
|
credits = 0.to_i - self.credits.to_i
|
|
197
199
|
#
|
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.60
|
|
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-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: websocket
|