Class: BlackStack::Client
- Inherits:
-
Object
- Object
- BlackStack::Client
- Defined in:
- lib/extend_client_by_invoicing_payments_processing.rb
Instance Method Summary collapse
- #add_bonus(id_user_creator, product_code, bonus_credits, description, expiration_time) ⇒ Object
-
#consume(product_code, number_of_credits = 1, description = nil) ⇒ Object
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.
-
#deserve_trial ⇒ Object
retorna true si este cliente no tiene ninguna generada con productos LGB2.
- #deserve_trial? ⇒ Boolean
-
#division ⇒ Object
TODO: el cliente deberia tener una FK a la tabla division.
- #get_balance ⇒ Object
- #get_movements(from_time, to_time, product_code = nil) ⇒ Object
-
#has_item(item_number, amount = nil) ⇒ Object
retorna true si existe algun item de factura relacionado al ‘plan’ (‘item_number’).
-
#plans ⇒ Object
retorna los planes estandar definidos en el array BlackStack::InvoicingPaymentsProcessing::plans_descriptor, y le concatena los arrays customizados de este cliente definidos en la tabla custom_plan.
Instance Method Details
#add_bonus(id_user_creator, product_code, bonus_credits, description, expiration_time) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/extend_client_by_invoicing_payments_processing.rb', line 63 def add_bonus(id_user_creator, product_code, bonus_credits, description, expiration_time) bonus_amount = 0 # balance = BlackStack::Balance.new(self.id, product_code) # amount = balance.amount.to_f # credits = balance.credits.to_f # if amount>=0 && credits>=0 # bonus_amount = (amount / credits) * bonus_credits ## else ## h = BlackStack::InvoicingPaymentsProcessing.product_descriptor(product_code) ## bonus_amount = h[:default_fee_per_unit].to_f # end m = BlackStack::Movement.new( :id_client => self.id, :create_time => now(), :type => BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS, :id_user_creator => id_user_creator, :description => description, :paypal1_amount => 0, :bonus_amount => bonus_amount, :amount => 0-bonus_amount, :credits => 0-bonus_credits, :profits_amount => 0, :product_code => product_code, :expiration_time => expiration_time ) m.id = guid() m.save end |
#consume(product_code, number_of_credits = 1, description = nil) ⇒ Object
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 13 14 |
# File 'lib/extend_client_by_invoicing_payments_processing.rb', line 12 def consume(product_code, number_of_credits=1, description=nil) DB.execute("exec reduceDebt '#{product_code.to_sql}', '#{self.id}', #{number_of_credits.to_s}, '#{description.to_s.to_sql}'") end |
#deserve_trial ⇒ Object
retorna true si este cliente no tiene ninguna generada con productos LGB2
30 31 32 |
# File 'lib/extend_client_by_invoicing_payments_processing.rb', line 30 def deserve_trial() self.disabled_for_trial_ssm != true end |
#deserve_trial? ⇒ Boolean
35 36 37 |
# File 'lib/extend_client_by_invoicing_payments_processing.rb', line 35 def deserve_trial? self.deserve_trial() end |
#division ⇒ Object
TODO: el cliente deberia tener una FK a la tabla division. La relacion no puede ser N-N. TODO: se debe preguntar a la central
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/extend_client_by_invoicing_payments_processing.rb', line 18 def division q = "SELECT d.id as id " + "FROM division d " + "JOIN user_division ud ON d.id=ud.id_division " + "JOIN [user] u ON u.id=ud.id_user " + "WHERE u.id_client = '#{self.id}' " row = DB[q].first BlackStack::Division.where(:id=>row[:id]).first end |
#get_balance ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/extend_client_by_invoicing_payments_processing.rb', line 40 def get_balance() n = 0 BlackStack::InvoicingPaymentsProcessing::products_descriptor.each { |code| n += BlackStack::Balance.new(self.id, code).amount } n end |
#get_movements(from_time, to_time, product_code = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/extend_client_by_invoicing_payments_processing.rb', line 49 def get_movements(from_time, to_time, product_code=nil) if from_time > to_time raise "From time must be earlier than To time" end if to_time.prev_year > from_time raise "There time frame cannot be longer than 1 year." end to_time += 1 ds = BlackStack::Movement.where(:id_client => self.id, :product_code=>product_code) if !product_code.nil? ds = BlackStack::Movement.where(:id_client => self.id) if product_code.nil? ds.where("create_time >= ? and create_time <= ?", from_time, to_time) end |
#has_item(item_number, amount = nil) ⇒ Object
retorna true si existe algun item de factura relacionado al ‘plan’ (‘item_number’). si el atributo ‘amount’ ademas es distinto a nil, se filtran items por ese monto.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/extend_client_by_invoicing_payments_processing.rb', line 94 def has_item(item_number, amount=nil) h = BlackStack::InvoicingPaymentsProcessing::plans_descriptor.select { |obj| obj[:item_number].to_s == item_number.to_s }.first raise "Plan not found" if h.nil? q = "SELECT i.id " + "FROM invoice i " # si el plan tiene un trial, entnces se pregunta si ya existe un item de factura por el importe del trial. # si el plan no tiene un trial, entnces se pregunta si ya existe un item de factura por el importe del plan. if amount.nil? q += "JOIN invoice_item t ON ( i.id=t.id_invoice AND t.item_number='#{item_number}' ) " else q += "JOIN invoice_item t ON ( i.id=t.id_invoice AND t.item_number='#{item_number}' AND t.amount=#{amount.to_s} ) " end q += "WHERE i.id_client='#{self.id}' " return !DB[q].first.nil? end |
#plans ⇒ Object
retorna los planes estandar definidos en el array BlackStack::InvoicingPaymentsProcessing::plans_descriptor, y le concatena los arrays customizados de este cliente definidos en la tabla custom_plan
119 120 121 122 123 124 125 |
# File 'lib/extend_client_by_invoicing_payments_processing.rb', line 119 def plans a = BlackStack::InvoicingPaymentsProcessing::plans_descriptor self.customplans.each { |p| a << p.to_hash } a end |