Class: MonthSalesDecorator
- Inherits:
-
BuisnessDecorator
- Object
- BuisnessDecorator
- MonthSalesDecorator
- Defined in:
- lib/sales_and_orders_decorator.rb
Overview
a concrete decorator for a month sale stores the sales details calculated in the database with the below functionality
Instance Method Summary collapse
-
#common_method ⇒ Object
Common logic to sort the products for a period of last one month time line.
-
#initialize(root_sales) ⇒ MonthSalesDecorator
constructor
method used to initialise the month sales object with component class object and the sales array.
-
#main_method ⇒ Object
this method provides the logical methods of sequencing the methods to calculate the sales details of the product for one month.
Methods inherited from BuisnessDecorator
#check, #check_foodType, #check_offer, #check_profit, #nonOfferedSale_counter_method, #nonVegCounter_method, #offeredSale_counter_method, #profit_counter_method, #sales_array, #totalSale_counter_method, #totalSale_quantity_method, #vegCounter_method
Constructor Details
#initialize(root_sales) ⇒ MonthSalesDecorator
method used to initialise the month sales object with component class object and the sales array
255 256 257 258 |
# File 'lib/sales_and_orders_decorator.rb', line 255 def initialize(root_sales) super(root_sales) @product_sale = Wsale.all end |
Instance Method Details
#common_method ⇒ Object
Common logic to sort the products for a period of last one month time line.
261 262 263 264 265 266 267 268 |
# File 'lib/sales_and_orders_decorator.rb', line 261 def common_method @product_sale.each do |product| sale_boolean = product.created_at.between?(Time.now.midnight-1.month,Time.now.midnight) if(sale_boolean) @root_sales.sales_array << product end end end |
#main_method ⇒ Object
this method provides the logical methods of sequencing the methods to calculate the sales details of the product for one month.
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/sales_and_orders_decorator.rb', line 271 def main_method common_method @root_sales.sales_array.each do |sd| totalSale_counter_method(sd) profit_counter_method(sd) vegCounter_method(sd) nonVegCounter_method(sd) offeredSale_counter_method(sd) nonOfferedSale_counter_method(sd) end #totalSale_counter += sd.totalSale #profit_counter += sd.profit #vegCounter += sd.vegSale #nonVegCounter += sd.nonVegSale #offeredSale_counter += sd.offeredSale #nonOfferedSale_counter += sd.nonOfferedSale @sale_on_order = Msale.new @sale_on_order.month = Date.today.strftime("Week : %W") @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 @sale_on_order.save end |