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 @@ <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.foc_sales") %> (<%= t("views.right_panel.detail.discount") %>) - <%= t("views.right_panel.detail.grand_total") %> +
<%= t("views.right_panel.detail.rnd_adj_sh") %> + + <%= t("views.right_panel.detail.grand_total") %> <%= t("views.right_panel.detail.rnd_adj_sh") %> - <%= t("views.right_panel.detail.grand_total") %> + <% if @print_settings.precision.to_i > 0 @@ -121,9 +122,10 @@ <%= number_with_precision(sale[:credit_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(sale[:foc_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> (<%= number_with_precision(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>) - <%= number_with_precision(sale[:grand_total].to_f + sale[:rounding_adj].to_f , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + + <%= number_with_precision(sale[:grand_total], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(sale[:rounding_adj].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(sale[:grand_total], precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <% count = count + 1 %> <% end %> @@ -144,12 +146,13 @@ <%= number_with_precision(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(foc, precision:precision,delimiter:delimiter) rescue '-'%> (<%= number_with_precision(discount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>) - <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + + <%= number_with_precision(grand_total, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(rounding_adj, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(grand_total, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + - <% total_tax = 0 %> + <% net = 0 %> <% unless @tax.empty? %> <% @tax.each do |tax| %> <% total_tax += tax.tax_amount.to_f %> @@ -161,7 +164,16 @@ <% end %> <% end %> - <% net = total - total_tax %> + + Discount + <%= number_with_precision(discount, precision:precision.to_i,delimiter:delimiter) rescue '-'%> +   + + + <% net = grand_total%> + <% net = grand_total- discount%> + <% net = net - rounding_adj%> + <% net = net - total_tax %> <%= t("views.right_panel.detail.net_amount") %> <%= number_with_precision(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%> diff --git a/app/views/reports/receipt_no/index.html.erb b/app/views/reports/receipt_no/index.html.erb index 9581d5df..5cecd715 100755 --- a/app/views/reports/receipt_no/index.html.erb +++ b/app/views/reports/receipt_no/index.html.erb @@ -72,6 +72,7 @@ <% grand_total = 0 %> <% old_grand_total = 0 %> + <% after_rounding = 0 %> <% total_tax = 0 %> <% guest_count = 0 %> <% total_sum = 0 %> @@ -82,13 +83,15 @@ <%if @sale_data %> <% @sale_data.each do |result| %> - <% grand_total = grand_total.to_f + result.grand_total.to_f %> - <% old_grand_total = old_grand_total.to_f + result.old_grand_total.to_f %> + <% grand_total +=result.grand_total.to_f %> + <% old_grand_total += result.grand_total_after_rounding() %> <% total_tax += result.total_tax.to_f %> <% total_sum += result.total_amount.to_f %> <% discount_amt += result.total_discount.to_f %> <% rounding_adj += result.rounding_adjustment.to_f %> + + <%= result.receipt_no rescue '-' %> @@ -101,12 +104,11 @@ <% result.sale_taxes.each do |tax| %> <%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%end%> - - <%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) %> - <%= result.rounding_adjustment.to_f rescue '-' %> <%= number_with_precision(result.grand_total_after_rounding(), precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + + <%= result.rounding_adjustment.to_f rescue '-' %> + <%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) %> - <% end %>   @@ -121,9 +123,10 @@ 0 <% end %> <% end %> - <%= number_with_precision(grand_total.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_with_precision(old_grand_total.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '0' %> + <%= rounding_adj.to_f rescue '-' %> - <%= number_with_precision(grand_total.to_f.round + rounding_adj, precision: precision.to_i ,delimiter: delimiter) rescue '0' %> + <%= number_with_precision(grand_total.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '-' %>   diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index a3937ec2..9b617d06 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -59,10 +59,11 @@ %> <% acc_arr = Array.new %> <% cate_arr = Array.new %> - + <% p_qty = 0 %> <% sub_qty = 0 %> <% sub_total = 0 %> <% other_sub_total = 0 %> + <% product_sub_total = 0 %> <% count = 0 %> <% total_price = 0 %> <% cate_count = 0 %> @@ -161,8 +162,47 @@ <% end %> <% end %> + + <% if @product.present?%> + + + Product +   + + + <% @product.each do |product| %> + <% if product.total_item > 0 + total_qty += product.total_item + end %> + <% grand_total +=product.grand_total + p_qty += product.total_item%> + +   + Product + <%= product.product_code rescue '-' %> + <%= product.product_name rescue '-' %> + <%= product.total_item rescue '-' %> + <%= number_with_precision(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + + + + <% product_sub_total += product.grand_total %> + + <% end %> + +   + Total Product Qty + <%= p_qty %> + + <%= t("views.right_panel.detail.sub_total") %> + <%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%> + + <%end%> + + - <% if @type == "other"%> + <% if @type == "other" || @other_charges.present?%> Other Charges @@ -216,7 +256,7 @@ end %> <% grand_total +=other.grand_total%> -   +   Other Charges <%= other.item_code rescue '-' %> <%= other.product_name rescue '-' %> diff --git a/db/migrate/20170325111608_create_menus.rb b/db/migrate/20170325111608_create_menus.rb index 84efdf2d..b1bef09e 100755 --- a/db/migrate/20170325111608_create_menus.rb +++ b/db/migrate/20170325111608_create_menus.rb @@ -3,6 +3,7 @@ class CreateMenus < ActiveRecord::Migration[5.1] create_table :menus do |t| t.string :name t.boolean :is_active, :null => false, :deafult => true + t.boolean :is_checksum, :default => false t.string :valid_days, :null => false, :default => "1,2,3,4,5,6,7" t.time :valid_time_from, :null => false, :default => "00:00:00" t.time :valid_time_to, :null => false, :default => "23:59:59"