diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index 92604b04..c49ba894 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -24,7 +24,7 @@ class Reports::SaleitemController < BaseReportController end @type = params[:sale_type] - @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type) + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type) @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @@ -62,7 +62,6 @@ class Reports::SaleitemController < BaseReportController def show from, to, report_type = get_date_range_from_params -puts "aaaaaaaaaaaaaaaaaaaaaaaaaa" @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index 39b9b021..e3c9376a 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -99,10 +99,10 @@ class Settings::MenusController < ApplicationController sheet.add_row ["Name",menu.name], :style=>title sheet.add_row - sheet.add_row ["Category Code", "Category Name", "Item Code", "Item Name", "Account", "Item AltName", "Taxable", "Attributes", "Options", "Instance Code", "Instance Name", "Price", "Is Default"], :style=>header_text + sheet.add_row ["Category Code", "Category Name", "Item Code", "Item Name", "Account", "Item AltName", "Taxable", "Attributes", "Options", "Instance Code", "Instance Name", "Instance Attribute", "Price", "Is Default"], :style=>header_text menu.menu_categories.each do |mc| - mc.menu_items.each do |mi| - attributes = "" + mc.menu_items.each do |mi| + attributes = "" i=0 if mi.item_attributes.length > 0 mi.item_attributes.each do |mia| @@ -119,8 +119,8 @@ class Settings::MenusController < ApplicationController options = "" i=0 if mi.item_options.length > 0 - mi.item_options.each do |mia| - option = MenuItemOption.find(mia) + mi.item_options.each do |mio| + option = MenuItemOption.find(mio) if i == mi.item_options.length - 1 options = options + option.name else @@ -131,68 +131,15 @@ class Settings::MenusController < ApplicationController end mi.menu_item_instances.each do |mii| - sheet.add_row [ mc.code, mc.name, mi.item_code, mi.name, mi.account.title, mi.alt_name, mi.taxable, attributes, options, mii.item_instance_code, mii.item_instance_name, mii.price, mii.is_default], :style=>wrap_text + attribute = "" + if mii.item_attributes.length > 0 + attribute = MenuItemAttribute.find(mii.item_attributes[0]).name + end + sheet.add_row [ mc.code, mc.name, mi.item_code, mi.name, mi.account.title, mi.alt_name, mi.taxable, attributes, options, mii.item_instance_code, mii.item_instance_name, attribute, mii.price, mii.is_default], :style=>wrap_text end end - end - - - # # Category - # menu.menu_categories.each do |mc| - # sheet.add_row ["Category"], :style=>wrap_text - # sheet.add_row %w(id menu_id code name alt_name order_by created_by menu_category_id is_available), :style=>header_text - # sheet.add_row [mc.id, mc.menu_id, mc.code, mc.name, mc.alt_name, mc.order_by, mc.created_by, mc.menu_category_id, mc.is_available], :style=>wrap_text - # sheet.add_row - - # # Menu Item - # mc.menu_items.each do |mi| - # sheet.add_row ["Menu Item"], :style=>wrap_text - # sheet.add_row %w(id item_code name alt_name image_path description information unit type menu_category_id item_attributes item_options account_id min_qty taxable is_sub_item is_available created_by), :style=>header_text - # sheet.add_row [mi.id,mi.item_code, mi.name, mi.alt_name, mi.image_path, mi.description, mi.information, mi.unit, mi.type, mi.menu_category_id, mi.item_attributes, mi.item_options, mi.account_id, mi.min_qty, mi.taxable, mi.is_sub_item, mi.is_available, mi.created_by], :style=>wrap_text - # sheet.add_row - - # # Menu Item Instance - # sheet.add_row ["Menu Item Instance"], :style=>wrap_text - # sheet.add_row %w(id menu_item_id item_instance_code item_instance_name item_attributes price is_on_promotion promotion_price is_available is_default), :style=>header_text - # mi.menu_item_instances.each do |mii| - # sheet.add_row [mii.id, mii.menu_item_id, mii.item_instance_code, mii.item_instance_name, mii.item_attributes, mii.price, mii.is_on_promotion, mii.promotion_price, mii.is_available, mii.is_default], :style=>wrap_text - # end - # sheet.add_row - # end - # end - end - - # # Account - # wb.add_worksheet(name: "Account") do |sheet| - # sheet.add_row %w(id title account_type discount point bonus rebate), :style=>header_text - # Account.all.each do |acc| - # sheet.add_row [acc.id, acc.title,acc.account_type,acc.discount,acc.point,acc.bonus,acc.rebate], :style=>wrap_text - # end - # end - - # # Item set - # wb.add_worksheet(name: "Item Set") do |sheet| - # sheet.add_row %w(id name alt_name min_selectable_qty max_selectable_qty), :style=>header_text - # ItemSet.all.each do |set| - # sheet.add_row [set.id,set.name, set.alt_name, set.min_selectable_qty, set.max_selectable_qty], :style=>wrap_text - # end - # end - - # # Item Options - # wb.add_worksheet(name: "Menu Item Options") do |sheet| - # sheet.add_row %w(id option_type name value), :style=>header_text - # MenuItemOption.all.each do |option| - # sheet.add_row [option.id, option.option_type, option.name, option.value], :style=>wrap_text - # end - # end - - # # Item Attributes - # wb.add_worksheet(name: "Menu Item Attributes") do |sheet| - # sheet.add_row %w(id attribute_type name value), :style=>header_text - # MenuItemAttribute.all.each do |attr| - # sheet.add_row [attr.id, attr.attribute_type,attr.name,attr.value], :style=>wrap_text - # end - # end + end + end end directory_name = "public/menus" diff --git a/app/models/menu.rb b/app/models/menu.rb index a9b88a85..98102789 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -148,9 +148,7 @@ class Menu < ApplicationRecord row = Hash[[sheet.row(3),sheet.row(ii)].transpose] menu_cat = MenuCategory.find_by_code(row["Category Code"]) if !menu_cat - menu_cat = MenuCategory.create({menu_id: imported_menu.id, code: row["Category Code"], name: row["Category Name"], alt_name: '', order_by: (ii - 3), created_by: created_by, menu_category_id: nil, is_available: 1}) - # else - # status = status + "Category Code already exists." + menu_cat = MenuCategory.create({menu_id: imported_menu.id, code: row["Category Code"], name: row["Category Name"], alt_name: '', order_by: (ii - 3), created_by: created_by, menu_category_id: nil, is_available: 1}) end # Menu Item Attributes @@ -191,20 +189,37 @@ class Menu < ApplicationRecord # status = status + "Item Code already exists for " + row["Item Name"] + "." end + instance_attr = [] menu_inst = MenuItemInstance.find_by_item_instance_code(row["Instance Code"]) if !menu_inst instance_name = '' if !row["Instance Name"].nil? instance_name = row["Instance Name"] end - imported_instance = MenuItemInstance.create(menu_item_id: menu_itm.id, item_instance_code: row["Instance Code"], item_instance_name: instance_name, item_attributes: [], price: row["Price"], is_on_promotion: false, promotion_price: 0, is_available: true, is_default: row["Is Default"]) - # else - # status = status + "Instance Code already exists for " + row["Instance Name"] + "." + + if !row["Attributes"].nil? + if !row["Instance Attribute"].nil? + attributes = row["Attributes"].split(',') + instance_attributes = row["Instance Attribute"].split(',') + attributes.each do |attr| + if attr == instance_attributes[0] + ins_attr = MenuItemAttribute.find_by_name(attr) + instance_attr.push(ins_attr.id) + end + end + end + end + + is_default = 0 + if !row["Is Default"].nil? + is_default = row["Is Default"] + end + imported_instance = MenuItemInstance.create(menu_item_id: menu_itm.id, item_instance_code: row["Instance Code"], item_instance_name: instance_name, item_attributes: instance_attr, price: row["Price"], is_on_promotion: false, promotion_price: 0, is_available: true, is_default: is_default) end end end # if status == '' - status="Menu Imported!" + status="Menu Imported!" # end return status diff --git a/app/models/sale.rb b/app/models/sale.rb index 0e19e65f..9e621737 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -906,7 +906,7 @@ def self.get_item_query(type) query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + " JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" + " JOIN menu_items mi ON mi.id = mii.menu_item_id" + - " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id" + + " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id" + " JOIN menu_categories mc ON mc.id = mi.menu_category_id ") # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id") @@ -942,10 +942,12 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) total_grand_total = 0 other_charges = self.get_other_charges() + product = self.get_product_sale() if shift.present? query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay') then (sale_payments.payment_amount) else 0 end) as card_amount, @@ -966,6 +968,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) elsif shift_sale_range.present? query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay') then (sale_payments.payment_amount) else 0 end) as card_amount, @@ -986,6 +989,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) else query = query.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay') then (sale_payments.payment_amount) else 0 end) as card_amount, @@ -1004,7 +1008,17 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) end - return query,other_charges, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount + return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount +end + +def self.get_product_sale() + query = Sale.select("i.account_id as account_id, " + + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," + + "i.status as status_type,"+ + " i.unit_price as unit_price,i.product_name as product_name,i.product_code as product_code") + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id") + query = query.joins("JOIN products p ON p.`item_code` = i.product_code") + query = query.group("i.product_code") end #product sale report query diff --git a/app/views/reports/dailysale/index.html.erb b/app/views/reports/dailysale/index.html.erb index f40c2d5d..85c7bed8 100755 --- a/app/views/reports/dailysale/index.html.erb +++ b/app/views/reports/dailysale/index.html.erb @@ -44,9 +44,10 @@