Class: BuisnessDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/sales_and_orders_decorator.rb

Overview

decorator class – this serves as the superclass for all the concrete decorators. This class provides the structure to all decorator class to define the logic

Instance Method Summary collapse

Constructor Details

#initialize(root_sales) ⇒ BuisnessDecorator

initialise all the values required to calculate the sales expenditure for the previous day.



61
62
63
64
65
66
67
68
69
70
# File 'lib/sales_and_orders_decorator.rb', line 61

def initialize(root_sales)
    @root_sales = root_sales
	@totalSale_counter = 0
	@totalSale_quantity = 0
	@vegCounter= 0
	@nonVegCounter= 0
	@offeredSale_counter = 0
	@nonOfferedSale_counter = 0
	@profit_counter = 0
end

Instance Method Details

#checkObject



146
147
148
# File 'lib/sales_and_orders_decorator.rb', line 146

def check
    
end

#check_foodTypeObject

to check thte food type sales and calculate the total sales of veg and non veg ordered



135
136
137
138
139
140
141
142
143
144
# File 'lib/sales_and_orders_decorator.rb', line 135

def check_foodType
    @root_sales.sales_array.each do |sd|
       prod = Product.find(sd.product_id)
       if(prod.foodType == "veg")
           @vegCounter +=sd.quantity
       else
           @nonVegCounter +=sd.quantity
       end
       end
end

#check_offerObject

to check thte offer availability and calculate the total sales of offered and non offered



123
124
125
126
127
128
129
130
131
132
# File 'lib/sales_and_orders_decorator.rb', line 123

def check_offer
    @root_sales.sales_array.each do |sd|
       prod = Product.find(sd.product_id)
       if(prod.offerPrice > 25)
           @offeredSale_counter +=sd.quantity
       else
           @nonOfferedSale_counter +=sd.quantity
       end
       end
end

#check_profitObject

returns the total profit sales with the root class total profit sales sold that is calculated already with the quantity of products sold



113
114
115
116
117
118
119
120
# File 'lib/sales_and_orders_decorator.rb', line 113

def check_profit
    @root_sales.sales_array.each do |sd|
           @totalSale_counter += sd.total_price
           @totalSale_quantity += sd.quantity
       end
       @totalProductSold = @totalSale_quantity * 25
       @profit_counter = @totalSale_counter - @totalProductSold
end

#common_methodObject

Common logic to sort the products for the previous 24 hrs time line.



151
152
153
154
155
156
157
158
# File 'lib/sales_and_orders_decorator.rb', line 151

def common_method
    @product_sale.each do |product|
       sale_boolean = product.created_at.between?(Time.now.midnight-1.day,Time.now.midnight)
       if(sale_boolean)
           @root_sales.sales_array << product
       end
       end
end

#main_methodObject

main method provides the sequence of all other method followed to generate a sales calculation



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/sales_and_orders_decorator.rb', line 161

def main_method
    common_method
    check_profit
    check_offer
    check_foodType
    @sale_on_order.totalSale = @totalSale_counter
    @sale_on_order.profit = @profit_counter
       @sale_on_order.nonVegSale = @nonVegCounter
       @sale_on_order.vegSale = @vegCounter
       @sale_on_order.offeredSale = @offeredSale_counter
       @sale_on_order.nonOfferedSale = @nonOfferedSale_counter
end

#nonOfferedSale_counter_method(sd) ⇒ Object

returns the total non offered type quantity sales with the root class total non offered pizza quantity sales sold that is calculated already



108
109
110
# File 'lib/sales_and_orders_decorator.rb', line 108

def nonOfferedSale_counter_method(sd)
    @nonOfferedSale_counter += sd.nonOfferedSale
end

#nonVegCounter_method(sd) ⇒ Object

returns the total non veg type quantity sales with the root class total veg pizza quantity sales sold that is calculated already



98
99
100
# File 'lib/sales_and_orders_decorator.rb', line 98

def nonVegCounter_method(sd)
    @nonVegCounter += sd.nonVegSale
end

#offeredSale_counter_method(sd) ⇒ Object

returns the total offered type quantity sales with the root class total offered pizza quantity sales sold that is calculated already



103
104
105
# File 'lib/sales_and_orders_decorator.rb', line 103

def offeredSale_counter_method(sd)
    @offeredSale_counter += sd.offeredSale
end

#profit_counter_method(sd) ⇒ Object

returns the total profit sales with the root class total profit of the sales sold which is calculated already



88
89
90
# File 'lib/sales_and_orders_decorator.rb', line 88

def profit_counter_method(sd)
    @profit_counter += sd.profit
end

#sales_arrayObject

returns the sales array from the component class



73
74
75
# File 'lib/sales_and_orders_decorator.rb', line 73

def sales_array
	return @root_sales.sales_array
end

#totalSale_counter_method(sd) ⇒ Object

returns the total sales with the root class total sales which is calculated already



78
79
80
# File 'lib/sales_and_orders_decorator.rb', line 78

def totalSale_counter_method(sd)
    @totalSale_counter += sd.totalSale
end

#totalSale_quantity_methodObject

returns the total quantity sales with the root class total quantity sales sold which is calculated already



83
84
85
# File 'lib/sales_and_orders_decorator.rb', line 83

def totalSale_quantity_method
	return @totalSale_quantity
end

#vegCounter_method(sd) ⇒ Object

returns the total veg type quantity sales with the root class total veg pizza quantity sales sold that is calculated already



93
94
95
# File 'lib/sales_and_orders_decorator.rb', line 93

def vegCounter_method(sd)
    @vegCounter += sd.vegSale
end