From ce7d15c2d4e3daf492cdac98cefdeb764e4b89ab Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 21 Aug 2017 11:41:42 +0630 Subject: [PATCH 01/10] update dashboard --- app/views/home/dashboard.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 511cd500..0df28c6f 100644 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -256,7 +256,7 @@ font-weight: 400; text-transform: uppercase; transition: color 0.3s ease; - line-height: 48px; + /*line-height: 48px;*/ } .card .card-content { @@ -264,7 +264,7 @@ border-radius: 0 0 2px 2px; background-clip: padding-box; box-sizing: border-box; - height: 120px; + /*height: 120px;*/ transition: color 0.3s ease; text-align: center; } From 2b0dcd4ab938c3dd1c0a2df07c74cebfea463270 Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 21 Aug 2017 16:50:24 +0630 Subject: [PATCH 02/10] update and fix --- app/controllers/settings/set_menu_items_controller.rb | 2 +- app/controllers/settings/simple_menu_items_controller.rb | 2 +- app/pdf/crm_order_pdf.rb | 4 ++-- app/pdf/order_item_pdf.rb | 4 ++-- app/pdf/order_summary_pdf.rb | 4 ++-- app/pdf/queue_no_pdf.rb | 4 ++-- app/pdf/receipt_bill_pdf.rb | 4 ++-- app/views/api/restaurant/menu/_menu_item.json.jbuilder | 1 + app/views/settings/set_menu_items/_form.html.erb | 2 ++ app/views/settings/simple_menu_items/_form.html.erb | 2 ++ db/migrate/20170331024749_create_menu_items.rb | 1 + db/seeds.rb | 8 ++++++-- 12 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/controllers/settings/set_menu_items_controller.rb b/app/controllers/settings/set_menu_items_controller.rb index 4f451de5..a9e91a94 100644 --- a/app/controllers/settings/set_menu_items_controller.rb +++ b/app/controllers/settings/set_menu_items_controller.rb @@ -132,6 +132,6 @@ class Settings::SetMenuItemsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_menu_item_params - params.require(:set_menu_item).permit(:item_code, :name, :alt_name, :type, :image_path, :menu_category_id,:account_id , :item_attributes, :item_options, :min_qty, :is_sub_item, :is_available, :created_by, :item_sets) + params.require(:set_menu_item).permit(:item_code, :name, :alt_name, :type, :image_path, :menu_category_id,:account_id , :item_attributes, :item_options, :min_qty, :is_sub_item, :is_available, :created_by, :item_sets, :unit) end end diff --git a/app/controllers/settings/simple_menu_items_controller.rb b/app/controllers/settings/simple_menu_items_controller.rb index 4cf9318c..418cc2b8 100644 --- a/app/controllers/settings/simple_menu_items_controller.rb +++ b/app/controllers/settings/simple_menu_items_controller.rb @@ -154,6 +154,6 @@ class Settings::SimpleMenuItemsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_menu_item_params - params.require(:simple_menu_item).permit(:item_code, :name, :alt_name, :type, :image_path, :menu_category_id, :account_id, :item_attributes, :item_options, :min_qty, :is_sub_item, :is_available, :created_by, :item_sets) + params.require(:simple_menu_item).permit(:item_code, :name, :alt_name, :type, :image_path, :menu_category_id, :account_id, :item_attributes, :item_options, :min_qty, :is_sub_item, :is_available, :created_by, :item_sets, :unit) end end diff --git a/app/pdf/crm_order_pdf.rb b/app/pdf/crm_order_pdf.rb index a7f85098..22a381ca 100644 --- a/app/pdf/crm_order_pdf.rb +++ b/app/pdf/crm_order_pdf.rb @@ -1,8 +1,8 @@ class CrmOrderPdf < Prawn::Document attr_accessor :receipt_width,:price_column_width,:p_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_column_width,:item_description_width def initialize(booking,order_items,printer_settings) - self.page_width = PrintSetting.where("name = ?","CRM Order").first.page_width - self.page_height = PrintSetting.where("name = ?","CRM Order").first.page_height + self.page_width = printer_settings.page_width + self.page_height = printer_settings.page_height self.margin = 10 # self.price_width = self.p_width / 2 self.price_width=80 diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 7b2e350b..4b9fb821 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -2,8 +2,8 @@ class OrderItemPdf < Prawn::Document include ActionView::Helpers::NumberHelper attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_item, print_status, options, alt_name) - self.page_width = PrintSetting.where("name = ?","OrderItemPdf").first.page_width - self.page_height = PrintSetting.where("name = ?","OrderItemPdf").first.page_height + self.page_width = printer_settings.page_width + self.page_height = printer_settings.page_height self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 902c68ad..53248ebb 100644 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -2,8 +2,8 @@ class OrderSummaryPdf < Prawn::Document include ActionView::Helpers::NumberHelper attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name) - self.page_width = PrintSetting.where("name = ?","Order Summary").first.page_width - self.page_height = PrintSetting.where("name = ?","Order Summary").first.page_height + self.page_width = printer_settings.page_width + self.page_height = printer_settings.page_height self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 diff --git a/app/pdf/queue_no_pdf.rb b/app/pdf/queue_no_pdf.rb index cda410ca..49e13bd9 100644 --- a/app/pdf/queue_no_pdf.rb +++ b/app/pdf/queue_no_pdf.rb @@ -1,8 +1,8 @@ class QueueNoPdf < Prawn::Document attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(printer_settings, queue) - self.page_width = PrintSetting.where("name = ?","Queue No").first.page_width - self.page_height = PrintSetting.where("name = ?","Queue No").first.page_height + self.page_width = printer_settings.page_width + self.page_height = printer_settings.page_height self.margin = 5 self.price_width = 35 self.qty_width = 20 diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 809f7678..1d9b3f4d 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -2,8 +2,8 @@ class ReceiptBillPdf < Prawn::Document include ActionView::Helpers::NumberHelper attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status) - self.page_width = PrintSetting.where("name = ?","Receipt Bill").first.page_width - self.page_height = PrintSetting.where("name = ?","Receipt Bill").first.page_height + self.page_width = printer_settings.page_width + self.page_height = printer_settings.page_height self.margin = 5 self.price_width = 40 self.qty_width = 20 diff --git a/app/views/api/restaurant/menu/_menu_item.json.jbuilder b/app/views/api/restaurant/menu/_menu_item.json.jbuilder index cd8648db..7a450850 100644 --- a/app/views/api/restaurant/menu/_menu_item.json.jbuilder +++ b/app/views/api/restaurant/menu/_menu_item.json.jbuilder @@ -35,6 +35,7 @@ json.account_id item.account_id json.min_qty item.min_qty json.is_available item.is_available json.is_sub_item item.is_sub_item +json.unit item.unit json.item_sets item.item_sets json.attributes attr_format json.options item.item_options diff --git a/app/views/settings/set_menu_items/_form.html.erb b/app/views/settings/set_menu_items/_form.html.erb index f243fb74..33be7f3a 100644 --- a/app/views/settings/set_menu_items/_form.html.erb +++ b/app/views/settings/set_menu_items/_form.html.erb @@ -16,6 +16,8 @@ <%= f.input :is_sub_item, :class => "form-control" %> + <%= f.input :unit, :collection => Lookup.collection_of("unit") ,:class => "form-control" %> + <%= f.input :item_attributes, :collection => @item_attributes, :input_html => { :multiple => true }, :class => "form-control item_attributes" %> <%= f.input :item_options, :collection => @item_options, :input_html => { :multiple => true }, :class => "form-control item_options" %> diff --git a/app/views/settings/simple_menu_items/_form.html.erb b/app/views/settings/simple_menu_items/_form.html.erb index 721c7230..82ef5f17 100644 --- a/app/views/settings/simple_menu_items/_form.html.erb +++ b/app/views/settings/simple_menu_items/_form.html.erb @@ -16,6 +16,8 @@ <%= f.input :is_sub_item, :class => "form-control" %> + <%= f.input :unit, :collection => Lookup.collection_of("unit") ,:class => "form-control" %> + <%= f.input :item_attributes, :collection => @item_attributes, :input_html => { :multiple => true }, :class => "form-control item_attributes" %> <%= f.input :item_options, :collection => @item_options, :input_html => { :multiple => true }, :class => "form-control item_options" %> diff --git a/db/migrate/20170331024749_create_menu_items.rb b/db/migrate/20170331024749_create_menu_items.rb index 75897d52..3ab06a94 100644 --- a/db/migrate/20170331024749_create_menu_items.rb +++ b/db/migrate/20170331024749_create_menu_items.rb @@ -7,6 +7,7 @@ class CreateMenuItems < ActiveRecord::Migration[5.1] t.string :image_path t.text :description t.string :information + t.string :unit t.string :type, :null => false, :default => "SimpleMenuItem" t.references :menu_category, foreign_key: true t.json :item_attributes diff --git a/db/seeds.rb b/db/seeds.rb index bf458f2a..27859c89 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -95,8 +95,12 @@ float_value = Lookup.create([{lookup_type:'float_value', name: '500', value: '50 # customer type customer_type = Lookup.create([{lookup_type:'customer_type', name: 'Dinein', value: 'Dinein'}, - {lookup_type:'customer_type', name: 'Takeaway', value: 'Takeaway'}, - {lookup_type:'customer_type', name: 'Delivery', value: 'Delivery'}]) + {lookup_type:'customer_type', name: 'Takeaway', value: 'Takeaway'}, + {lookup_type:'customer_type', name: 'Delivery', value: 'Delivery'}]) + +#unit +units = Lookup.create([{lookup_type:'unit', name: 'PCS', value: 'pcs'}, + {lookup_type:'unit', name: 'KG', value: 'kg'}]) # Default CUSTOMER customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000", customer_type:"Dinein", tax_profiles:["2", "1"]}) From 7a1668ca829e6bfbedac422f16d1610b70e7a53d Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 21 Aug 2017 18:44:40 +0630 Subject: [PATCH 03/10] re-fixed for customer button --- app/views/origami/home/show.html.erb | 5 +++-- app/views/origami/rooms/show.html.erb | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index c60e8917..0e755dd9 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -306,9 +306,9 @@ - <% if @dining.bookings.length >= 1 %> - + <% if @dining.bookings.length >= 1 %> <% if @status_order == 'order' && @status_sale != 'sale' %> + @@ -318,6 +318,7 @@ <% else %> + diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 39d55757..686c675f 100644 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -303,7 +303,6 @@ <% if @room.bookings.length >= 1 %> - <% if @status_order == 'order' && @status_sale != 'sale' %> From a400bb5a0e01e8c3e9425f61660d4487214bf908 Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 22 Aug 2017 11:44:31 +0630 Subject: [PATCH 04/10] remove extra menu image --- .../public/image/menu_images/icons8-Food-100.png | Bin 5031 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 public/public/image/menu_images/icons8-Food-100.png diff --git a/public/public/image/menu_images/icons8-Food-100.png b/public/public/image/menu_images/icons8-Food-100.png deleted file mode 100644 index a77e616915a0092eebe86fb03492d432df762dd9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5031 zcmV;Y6IkqtP)=6J8S`pvvI{d)Rc zqnXhtMORTsdVT-;JNo;&zb3eo3Tg&OLG|WNXK)9Q0$T*GfNWX6<9QJBLV@+$TX!fb z2+*cdy!wx?)wg*oWS{HbH#F4+D4wSTwVBpMDB1!lUVZro^%rDy*aGs(#-<9Yl0B5t zd6_m|P~|k#H@sHAGt)k8-O#id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z3uVS&o*7FbpQVE|A{>L^er0>BUG-Y+gi_1t@0IXCmK zGf)Pv*@U#BxB#Gqg0|!npiF!rGC-Uxz8L|Myr9G0I!vPg*=#c*KK--veZQ&8Hj1CL zo-v(Pwn!!cBA~mzvwdB&E8-bu-~p+aUX58R7kRGf@PEDwEta_YmQ_H!zEf2^r4l7m zt5G^*3W}=AJ$GEps6}H4pTB}|=XFH7Zb0o1JJ!Y2N+pC9xsW+LAQSJMihDjc&-1uW z?AnL$&A#jcVt4zLgn}rUIuS)x6)2uorT?6(r1lMBsOttI-M0|w>PGBF;t_d1x#{|u z_O0Mp7Vn%1m5sr;x%Z%WYSpkPAk)b)$}tLJloS4Q7y8d$PF3e2(52tDdG4ST1u_4t zbzuLyrNN#)oNV4_X3Lt|%bN|RJ+~4{ne_<=w~podd(Znv(f`pUy_sBCi^V`ZUL92D z-aCTci`NpvcR2y?OQ`dJOkVRyuIJZx{rzVyVju~Kmy_nc8vq~%Fmt<(U_Jdl%m8L$ zhxuUrnG7b+Wpd(i6sd%bi5+y9Jg3&ezS!=(0gfQ+uoV*1(-D?J>nU0&aS Date: Tue, 22 Aug 2017 14:11:25 +0630 Subject: [PATCH 05/10] fix menu edit --- app/controllers/settings/menu_item_instances_controller.rb | 4 ++-- app/views/settings/set_menu_items/edit.html.erb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/settings/menu_item_instances_controller.rb b/app/controllers/settings/menu_item_instances_controller.rb index 0d276602..fbe1b672 100644 --- a/app/controllers/settings/menu_item_instances_controller.rb +++ b/app/controllers/settings/menu_item_instances_controller.rb @@ -55,7 +55,7 @@ class Settings::MenuItemInstancesController < ApplicationController sets = ItemSet.find(params[:menu_item_instance][:item_sets]) if sets.count > 0 - @settings_menu_item.item_sets = sets + @settings_menu_item_instances.item_sets = sets end end @@ -92,7 +92,7 @@ class Settings::MenuItemInstancesController < ApplicationController sets = ItemSet.find(params[:menu_item_instance][:item_sets]) if sets.count > 0 - @settings_menu_item.item_sets = sets + @settings_menu_item_instances.item_sets = sets end end diff --git a/app/views/settings/set_menu_items/edit.html.erb b/app/views/settings/set_menu_items/edit.html.erb index 6a4eb567..bc9bc62b 100644 --- a/app/views/settings/set_menu_items/edit.html.erb +++ b/app/views/settings/set_menu_items/edit.html.erb @@ -16,13 +16,13 @@ $(function(){ <% @settings_menu_item.item_sets.each do |set| %> - $("#simple_menu_item_item_sets option[value='" + <%= set.id %> + "']").attr("selected","selected").css({'color':'#fff','background':'#215d9c'}); + $("#set_menu_item_item_sets option[value='" + <%= set.id %> + "']").attr("selected","selected").css({'color':'#fff','background':'#215d9c'}); <% end %> // After loaded - $("#simple_menu_item_item_sets").on('click', 'option', function(e){ + $("#set_menu_item_item_sets").on('click', 'option', function(e){ if($(this).attr("selected")){ $(this).removeAttr("selected"); $(this).css({'color':'#000','background':'#fff'}); From 94cc126969fa6b0f5df2e8ae5dd232e925dd02cb Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 22 Aug 2017 18:02:16 +0630 Subject: [PATCH 06/10] fix for pdf print setting --- app/pdf/order_item_pdf.rb | 4 ++-- app/pdf/order_summary_pdf.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 4b9fb821..64df3adb 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -2,8 +2,8 @@ class OrderItemPdf < Prawn::Document include ActionView::Helpers::NumberHelper attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_item, print_status, options, alt_name) - self.page_width = printer_settings.page_width - self.page_height = printer_settings.page_height + self.page_width = print_settings.page_width + self.page_height = print_settings.page_height self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 53248ebb..d23f2677 100644 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -2,8 +2,8 @@ class OrderSummaryPdf < Prawn::Document include ActionView::Helpers::NumberHelper attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name) - self.page_width = printer_settings.page_width - self.page_height = printer_settings.page_height + self.page_width = print_settings.page_width + self.page_height = print_settings.page_height self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 From 28dab9d3e06e27cc5829a851ae0225092251318e Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 23 Aug 2017 09:48:15 +0630 Subject: [PATCH 07/10] promotion --- app/models/promotion.rb | 147 ++++++++++++++++++++++++++++++++++++++++ app/models/shop.rb | 112 ------------------------------ 2 files changed, 147 insertions(+), 112 deletions(-) diff --git a/app/models/promotion.rb b/app/models/promotion.rb index b255ceec..3b4b61ed 100644 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -9,4 +9,151 @@ class Promotion < ApplicationRecord PROMO_TYPE2 = "Net_off" PROMO_TYPE3 = "Net_price" PROMO_TYPE4 = "Percentage" + + def self.promo_activate + saleObj = Sale.first # Test + current_day = Time.now.strftime("%Y-%m-%d") + current_time = Time.now.strftime('%H:%M:%S') + day = Date.today.wday + promoList = is_between_promo_datetime(current_day,current_time) + puts "promoList - " + promoList.size.to_s + if promoList.size > 0 + itemList = combine_item(saleObj) + is_promo_day(promoList,day, itemList) + end + end + + def self.is_between_promo_datetime(current_day,current_time) #database is not local time + promoList = Promotion.where("(TO_CHAR(promo_start_date, 'YYYY-MM-DD') <=? AND TO_CHAR(promo_end_date, 'YYYY-MM-DD') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time) + return promoList + end + + def self.combine_item(saleObj) + itemList = saleObj.sale_items.group(:product_code).sum(:qty) + end + + def self.is_promo_day(promoList, day, orderitemList) + puts "Today date - " + day.to_s + promoList.each do |promo| + dayresult = promo.promo_day.include?(day.to_s) + if dayresult + orderitemList.each do |item| + find_promo_item(promo, item) + end + end + end + end + + def self.find_promo_item(promo, orderitem) + if promo.original_product.to_s == orderitem[0].to_s + if promo.min_qty.to_i > orderitem[1].to_i + return false + else + check_promo_type(promo,orderitem) + end + end + end + + def self.check_promo_type(promo, orderitem) + if promo.promo_type == Promotion::PROMO_TYPE1 + same, foc_min_qty = check_giveaway_product(promo, orderitem[0]) + if same + give_promotion_same_product(orderitem[1], promo.min_qty, foc_min_qty, orderitem) + else + find_promo_item_in_orderlist + end + elsif promo.promo_type == Promotion::PROMO_TYPE2 + + elsif promo.promo_type == Promotion::PROMO_TYPE3 + + elsif promo.promo_type == Promotion::PROMO_TYPE4 + + end + end + + def self.check_giveaway_product(promo, orderitem) + promo.promotion_products.each do |promo_product| + if promo_product.item_code == orderitem + return true, promo_product.min_qty.to_i + else + return false, 0 + end + end + end + + def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem) + puts " Order qty: " + qty.to_s + " / promoqty: " + promoqty.to_s + " / giveaway: " + foc_min_qty.to_s + multiple = qty.to_i / promoqty.to_i # loop count + charge_qty = 0 + foc_qty = 0 + if multiple > 0 + multiple.times.each do |key| + if qty >= promoqty + charge_qty += promoqty + different = qty - promoqty + qty = different + if different == 0 + foc_qty += foc_min_qty + else + foc_qty += foc_min_qty + qty = qty - foc_min_qty + end + else + if multiple == foc_qty + charge_qty += qty + else + charge_qty += qty + end + end + end + else + charge_qty = qty + end + if qty == promoqty + update_existing_item(foc_qty, orderitem) + else + update_existing_item(foc_qty, orderitem) + end + puts "Charged - " + charge_qty.to_s + puts "FOC - " + foc_qty.to_s + end + + def find_promo_item_in_orderlist(promo_item_code, orderitemList) + orderitemList.each do |item| + if item.item_code == promo_item_code + give_promotion_second_product(item) + else + add_promotion_second_item + end + end + end + + def give_promotion_second_product(item, foc_min_qty) + if item.qty > foc_min_qty + + else + + end + end + + def self.update_existing_item(foc_qty, item) + + sale_item = SaleItem.new + sale_item.product_code = item.item_code + sale_item.product_name = item.item_name + " (promotion)" + sale_item.product_alt_name = item.alt_name + sale_item.account_id = item.account_id + sale_item.remark = " Promotion " + + sale_item.qty = foc_qty + sale_item.unit_price = item.price + sale_item.taxable_price = item.price + sale_item.is_taxable = item.taxable + + sale_item.price = foc_qty * item.price + end + + def self.add_promotion_second_item + + end end diff --git a/app/models/shop.rb b/app/models/shop.rb index dbb0930e..24f4bc1e 100644 --- a/app/models/shop.rb +++ b/app/models/shop.rb @@ -1,116 +1,4 @@ class Shop < ApplicationRecord - def promo_activate - current_day = Time.now.strftime("%Y-%d-%m") - current_time = Time.now.strftime('%H:%M') - day = Date.today.wday - promoList = is_between_promo_datetime(current_day,current_time) - if promoList.size > 0 - itemList = combine_item(saleObj) - is_promo_day(promoList,day, itemList) - end - end - def is_between_promo_datetime(current_day,current_time) - promoList = Promotion.where('( promo_start_date < ? AND promo_end_date > ?) AND (promo_start_time < ? AND promo_end_time > ?)', current_day, current_day, current_time, current_time) - return promoList - end - - def combine_item(saleObj) - itemList = saleObj.sale_items.group(:product_code).sum(:qty) - end - - def is_promo_day(promoList, day, orderitemList) - promoList.each do |promo| - dayresult = promo.promo_day.include?(day) - if dayresult - orderitemList.each do |item| - find_promo_item(promo, item) - end - end - end - end - - def find_promo_item(promo, orderitem) - if promo.prouduct_item == orderitem - if promo.minmum_qty < orderitem.qty - return false - else - same, promo_item_code = check_giveaway_product(promo, orderitem) - if same - give_promotion_same_product - else - find_promo_item_in_orderlist - end - end - end - end - - def check_giveaway_product(promo, orderitem) - promo.promotion_products.each do |promo_product| - if promo_product.item_code == orderitem.item_code - return true, promo_product.item_code - else - return false, promo_product.item_code - end - end - end - - def self.give_promotion_same_product(qty, promoqty, foc_min_qty) - multiple = qty / promoqty # loop count - charge_qty = 0 - foc_qty = 0 - if multiple > 0 - multiple.times.each do |key| - if qty >= promoqty - charge_qty += promoqty - different = qty - promoqty - qty = different - if different == 0 - Shop.add_promotion_item - foc_qty += foc_min_qty - else - foc_qty += foc_min_qty - qty = qty - foc_min_qty - end - else - if multiple == foc_qty - charge_qty += qty - else - charge_qty += qty - end - end - end - else - charge_qty = qty - end - puts "Charged - " + charge_qty.to_s - puts "FOC - " + foc_qty.to_s - end - - def find_promo_item_in_orderlist(promo_item_code, orderitemList) - orderitemList.each do |item| - if item.item_code == promo_item_code - give_promotion_second_product(item) - else - add_promotion_second_item - end - end - end - - def give_promotion_second_product(item, foc_min_qty) - if item.qty > foc_min_qty - - else - - end - end - - def self.add_promotion_item - - end - - def self.add_promotion_second_item - - end end From eedf6c39a1c33abb99fd6e516eb499a45734e8fc Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 23 Aug 2017 10:12:41 +0630 Subject: [PATCH 08/10] promotion + merge with master --- app/controllers/api/bill_controller.rb | 1 + app/models/promotion.rb | 3 +-- app/models/sale.rb | 24 ++++++++++++------------ app/views/origami/home/index.html.erb | 14 ++++++-------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index eba40816..7ee80f00 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -24,6 +24,7 @@ class Api::BillController < Api::ApiController @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier) end + # Promotion.promo_activate(@sale) else @status = false @error_message = "No Current Open Shift" diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 3b4b61ed..778f7638 100644 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -10,8 +10,7 @@ class Promotion < ApplicationRecord PROMO_TYPE3 = "Net_price" PROMO_TYPE4 = "Percentage" - def self.promo_activate - saleObj = Sale.first # Test + def self.promo_activate(saleObj) current_day = Time.now.strftime("%Y-%m-%d") current_time = Time.now.strftime('%H:%M:%S') day = Date.today.wday diff --git a/app/models/sale.rb b/app/models/sale.rb index 71994ca1..9927251d 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -298,8 +298,8 @@ class Sale < ApplicationRecord customer = Customer.find(sale.customer_id) # #Creat new tax records tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id + customer.tax_profiles.each do |cus_tax| + if cus_tax.to_i == tax.id sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -311,7 +311,7 @@ class Sale < ApplicationRecord rate = tax.rate divided_value = (100 + rate)/rate sale_tax.tax_payable_amount = total_tax / divided_value - else + else sale_tax.tax_payable_amount = total_tax * tax.rate / 100 total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount end @@ -319,7 +319,7 @@ class Sale < ApplicationRecord # total_taxable = total_taxable + sale_tax.tax_payable_amount sale_tax.inclusive = tax.inclusive - sale_tax.save + sale_tax.save end end end @@ -338,13 +338,13 @@ class Sale < ApplicationRecord total_tax_amount = 0 #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") - - customer = Customer.find(self.customer_id) + customer = Customer.find(self.customer_id) + puts customer #Create new tax records tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id + customer.tax_profiles.each do |cus_tax| + if cus_tax.to_i == tax.id sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -356,16 +356,16 @@ class Sale < ApplicationRecord rate = tax.rate divided_value = (100 + rate)/rate sale_tax.tax_payable_amount = total_tax / divided_value - else + else sale_tax.tax_payable_amount = total_tax * tax.rate / 100 total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount end - + #new taxable amount is standard rule for step by step # total_taxable = total_taxable + sale_tax.tax_payable_amount sale_tax.inclusive = tax.inclusive - sale_tax.save + sale_tax.save end end end @@ -596,7 +596,7 @@ def self.get_item_query() query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id") query = query.group('i.product_code ').order("mi.account_id, mi.menu_category_id") -end +end def self.get_by_shift_items(shift_sale_range, shift, from, to, status) # date_type_selection = get_sql_function_for_report_type(report_type) diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 05094504..2742f249 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -108,17 +108,15 @@ - <%if current_login_employee.role == "cashier" && @shop.quick_sale_summary == true%> - - <%end%> + - - - <%if current_login_employee.role == "administrator" || current_login_employee.role == "manager" %> - <%end%> - + From de769f3faf46e22cc6b477cd859fa9206c4fef82 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 23 Aug 2017 17:37:13 +0630 Subject: [PATCH 09/10] promotion --- app/controllers/api/bill_controller.rb | 2 +- app/models/promotion.rb | 127 ++++++++++++++----------- 2 files changed, 74 insertions(+), 55 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 7ee80f00..2b323d0f 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -24,7 +24,7 @@ class Api::BillController < Api::ApiController @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier) end - # Promotion.promo_activate(@sale) + Promotion.promo_activate(@sale) else @status = false @error_message = "No Current Open Shift" diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 778f7638..32b40ec4 100644 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -6,8 +6,8 @@ class Promotion < ApplicationRecord accepts_nested_attributes_for :promotion_products , :allow_destroy => true PROMO_TYPE1 = "Quantity" - PROMO_TYPE2 = "Net_off" - PROMO_TYPE3 = "Net_price" + PROMO_TYPE2 = "Net_off" # 3000 => - 500 => 2500 [total] + PROMO_TYPE3 = "Net_price" # 1800 => 1000 => 1000 PROMO_TYPE4 = "Percentage" def self.promo_activate(saleObj) @@ -18,7 +18,7 @@ class Promotion < ApplicationRecord puts "promoList - " + promoList.size.to_s if promoList.size > 0 itemList = combine_item(saleObj) - is_promo_day(promoList,day, itemList) + is_promo_day(promoList,day, itemList, saleObj.sale_id) end end @@ -31,63 +31,63 @@ class Promotion < ApplicationRecord itemList = saleObj.sale_items.group(:product_code).sum(:qty) end - def self.is_promo_day(promoList, day, orderitemList) + def self.is_promo_day(promoList, day, orderitemList, sale_id) puts "Today date - " + day.to_s promoList.each do |promo| dayresult = promo.promo_day.include?(day.to_s) if dayresult orderitemList.each do |item| - find_promo_item(promo, item) + find_promo_item(promo, item, sale_id) end end end end - def self.find_promo_item(promo, orderitem) + def self.find_promo_item(promo, orderitem, sale_id) if promo.original_product.to_s == orderitem[0].to_s if promo.min_qty.to_i > orderitem[1].to_i return false else - check_promo_type(promo,orderitem) + check_promo_type(promo,orderitem, sale_id) end end end - def self.check_promo_type(promo, orderitem) + def self.check_promo_type(promo, orderitem, sale_id) + same, promo_product = check_giveaway_product(promo, orderitem[0]) if promo.promo_type == Promotion::PROMO_TYPE1 - same, foc_min_qty = check_giveaway_product(promo, orderitem[0]) if same - give_promotion_same_product(orderitem[1], promo.min_qty, foc_min_qty, orderitem) + give_promotion_same_product(orderitem[1], promo.min_qty, promo_product.min_qty, orderitem, sale_id) else - find_promo_item_in_orderlist + give_promotion_second_product(orderitem[1], promo.min_qty, promo_product.item_code, orderitem, sale_id) end elsif promo.promo_type == Promotion::PROMO_TYPE2 - + give_promotion_nett_off(same,promo_product,promo.min_qty, orderitem, sale_id) elsif promo.promo_type == Promotion::PROMO_TYPE3 - + # net price elsif promo.promo_type == Promotion::PROMO_TYPE4 - + # Percentage end end def self.check_giveaway_product(promo, orderitem) promo.promotion_products.each do |promo_product| if promo_product.item_code == orderitem - return true, promo_product.min_qty.to_i + return true, promo_product else - return false, 0 + return false, promo_product end end end - def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem) + def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem, sale_id) puts " Order qty: " + qty.to_s + " / promoqty: " + promoqty.to_s + " / giveaway: " + foc_min_qty.to_s multiple = qty.to_i / promoqty.to_i # loop count charge_qty = 0 foc_qty = 0 if multiple > 0 multiple.times.each do |key| - if qty >= promoqty + if qty > promoqty charge_qty += promoqty different = qty - promoqty qty = different @@ -98,61 +98,80 @@ class Promotion < ApplicationRecord qty = qty - foc_min_qty end else - if multiple == foc_qty - charge_qty += qty - else - charge_qty += qty - end + charge_qty += qty end end + if multiple == foc_qty + charge_qty += qty + end else - charge_qty = qty - end - if qty == promoqty - update_existing_item(foc_qty, orderitem) - else - update_existing_item(foc_qty, orderitem) + charge_qty += qty end + item = OrderItem.find_by_item_code(orderitem[0]) + update_existing_item(foc_qty, item, sale_id, "promotion", item.price) + puts "Charged - " + charge_qty.to_s puts "FOC - " + foc_qty.to_s end - - def find_promo_item_in_orderlist(promo_item_code, orderitemList) - orderitemList.each do |item| - if item.item_code == promo_item_code - give_promotion_second_product(item) - else - add_promotion_second_item - end - end + # AA - 10 # 3 # BB # orderList, #S34345 + def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id) + puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s + promotion_qty = orderitem_count.to_i / foc_min_qty.to_i # get foc item qty + item = OrderItem.find_by_item_code(promo_product) + update_existing_item(promotion_qty, item, sale_id, "promotion", item.price) end - def give_promotion_second_product(item, foc_min_qty) - if item.qty > foc_min_qty - - else - - end - end - - def self.update_existing_item(foc_qty, item) + def self.update_existing_item(foc_qty, item, sale_id, type, item_price) sale_item = SaleItem.new sale_item.product_code = item.item_code - sale_item.product_name = item.item_name + " (promotion)" + sale_item.product_name = item.item_name + "("+ type +")" sale_item.product_alt_name = item.alt_name sale_item.account_id = item.account_id - sale_item.remark = " Promotion " + sale_item.remark = type + sale_item.qty = foc_qty * (-1) + + sale_item.unit_price = item_price * (-1) + sale_item.taxable_price = item_price + sale_item.price = foc_qty * item_price * (-1) - sale_item.qty = foc_qty - sale_item.unit_price = item.price - sale_item.taxable_price = item.price sale_item.is_taxable = item.taxable + sale_item.sale_id = sale_id - sale_item.price = foc_qty * item.price + sale_item.save end - def self.add_promotion_second_item + + def self.give_promotion_nett_off(same, promo_product, foc_min_qty, orderitem, sale_id) + puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s + + if same + foc_qty = orderitem[1].to_i / foc_min_qty + item = OrderItem.find_by_item_code(orderitem[0]) + update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off) + else + foc_qty = find_second_item_qty(sale_id, promo_product.item_code) + item = OrderItem.find_by_item_code(promo_product.item_code) + update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off) + end + end + + def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, sale_id) end + + def self.give_promotion_discount() + + end + + def self.find_second_item_qty(sale_id, promo_item) + saleObj = Sale.find_by_sale_id(sale_id) + itemList = combine_item(saleObj) + itemList.each do |item| + if item[0] == promo_item + return item[1] + end + end + end + end From 688ce932cc0ed3b8f0f4c2aaecfa650dbcf0c7df Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 23 Aug 2017 18:07:58 +0630 Subject: [PATCH 10/10] promotion --- app/models/promotion.rb | 42 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 32b40ec4..ed727038 100644 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -61,12 +61,15 @@ class Promotion < ApplicationRecord else give_promotion_second_product(orderitem[1], promo.min_qty, promo_product.item_code, orderitem, sale_id) end + elsif promo.promo_type == Promotion::PROMO_TYPE2 give_promotion_nett_off(same,promo_product,promo.min_qty, orderitem, sale_id) + elsif promo.promo_type == Promotion::PROMO_TYPE3 - # net price + give_promotion_nett_price(same,promo_product,promo.min_qty, orderitem, sale_id) + elsif promo.promo_type == Promotion::PROMO_TYPE4 - # Percentage + give_promotion_nett_price(same,promo_product,promo.min_qty, orderitem, sale_id) end end @@ -125,7 +128,7 @@ class Promotion < ApplicationRecord sale_item = SaleItem.new sale_item.product_code = item.item_code - sale_item.product_name = item.item_name + "("+ type +")" + sale_item.product_name = item.item_name + "(promotion)" sale_item.product_alt_name = item.alt_name sale_item.account_id = item.account_id sale_item.remark = type @@ -157,11 +160,37 @@ class Promotion < ApplicationRecord end def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, sale_id) + puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s + if same + foc_qty = orderitem[1].to_i / foc_min_qty + item = OrderItem.find_by_item_code(orderitem[0]) + price = item.price - promo_product.net_price + update_existing_item(foc_qty, item, sale_id, "promotion nett price", price) + else + foc_qty = find_second_item_qty(sale_id, promo_product.item_code) + item = OrderItem.find_by_item_code(promo_product.item_code) + price = item.price - promo_product.net_price + update_existing_item(foc_qty, item, sale_id, "promotion nett price", price) + end end - def self.give_promotion_discount() - + def self.give_promotion_discount(same, promo_product, foc_min_qty, orderitem, sale_id) + puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s + + if same + foc_qty = orderitem[1].to_i / foc_min_qty + item = OrderItem.find_by_item_code(orderitem[0]) + total = orderitem[1].to_i * item.price + price = calculate_discount(total, promo_product.percentage) + update_existing_item(foc_qty, item, sale_id, "promotion discount", price) + else + foc_qty = find_second_item_qty(sale_id, promo_product.item_code) + item = OrderItem.find_by_item_code(promo_product.item_code) + total = item.price * foc_qty + price = calculate_discount(total, promo_product.percentage) + update_existing_item(foc_qty, item, sale_id, "promotion discount", price) + end end def self.find_second_item_qty(sale_id, promo_item) @@ -174,4 +203,7 @@ class Promotion < ApplicationRecord end end + def self.calculate_discount(total, discount) + self (total.to_i * discount.to_i) / 100 + end end