Class: WeekSalesDecorator

Inherits:
BuisnessDecorator show all
Defined in:
lib/sales_and_orders_decorator.rb

Overview

a concrete decorator for week sales stores the sales details calculated in the database with the below functionality

Instance Method Summary collapse

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) ⇒ WeekSalesDecorator

method used to initialise the week sales object with component class object and the sales array



206
207
208
209
# File 'lib/sales_and_orders_decorator.rb', line 206

def initialize(root_sales)
  super(root_sales)
  @product_sale = Dsale.all
end

Instance Method Details

#common_methodObject

Common logic to sort the products for a week time line.



212
213
214
215
216
217
218
219
# File 'lib/sales_and_orders_decorator.rb', line 212

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

#main_methodObject

this method provides the logical methods of sequencing the methods to calculate the sales details of the product for the last one week.



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/sales_and_orders_decorator.rb', line 222

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 = Wsale.new
       @sale_on_order.week = Date.today
    @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