From 4a0b88cfb92625e81f21427ce2dae5a195381ada Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 15 Feb 2018 10:42:02 +0630 Subject: [PATCH 01/98] update application for license --- app/controllers/application_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e66d7700..0966a573 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -38,11 +38,11 @@ class ApplicationController < ActionController::Base end else # check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end + if check_license + current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path + end end end From dff0a4798e56cfffcb162875f708a61103fc1c41 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 15 Feb 2018 12:11:54 +0630 Subject: [PATCH 02/98] add new line --- app/models/printer/cashier_station_printer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index e62ab4d1..fd1dc0cd 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -30,6 +30,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount) + filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" pdf.render_file filename self.print(filename, cashier_terminal.printer_name) From 35721cd9177b7244e0197e07b19df144a5781d9e Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 15 Feb 2018 12:15:39 +0630 Subject: [PATCH 03/98] remove space line --- app/models/printer/cashier_station_printer.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index e62ab4d1..3c6dac88 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -34,6 +34,4 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker pdf.render_file filename self.print(filename, cashier_terminal.printer_name) end - - end From d8d119edd6c7610664a6c7d8150c2cb4a50c017f Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 15 Feb 2018 13:27:45 +0630 Subject: [PATCH 04/98] release_c1 --- app/models/printer/cashier_station_printer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 2577e8c1..fc79934d 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -35,4 +35,5 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker pdf.render_file filename self.print(filename, cashier_terminal.printer_name) end + #release_c1 end From 016d3f4187c91c5a9aaf94f8eda777f2dc2aa6f5 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 15 Feb 2018 13:29:52 +0630 Subject: [PATCH 05/98] sqa --- app/models/printer/cashier_station_printer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 3c6dac88..dc0d79d1 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -34,4 +34,5 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker pdf.render_file filename self.print(filename, cashier_terminal.printer_name) end + #sqa end From e50915aa3b38087da30b4f740b9461fbf75960a8 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 15 Feb 2018 18:35:33 +0630 Subject: [PATCH 06/98] Add Dinein, Takeway, Change Total to Gross Sale,Grand Total --- app/controllers/application_controller.rb | 14 +- app/controllers/origami/shifts_controller.rb | 8 +- app/models/printer/cashier_station_printer.rb | 8 +- app/models/shift_sale.rb | 14 + app/pdf/close_cashier_customerize_pdf.rb | 433 ++++++++++++++++++ app/pdf/close_cashier_pdf.rb | 6 +- 6 files changed, 467 insertions(+), 16 deletions(-) create mode 100644 app/pdf/close_cashier_customerize_pdf.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0966a573..505a38b3 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,13 +36,13 @@ class ApplicationController < ActionController::Base # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] end - else - # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # else + # # check for license file + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index cb2cc830..8bb684e9 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -73,12 +73,15 @@ class Origami::ShiftsController < BaseOrigamiController @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') @total_member_discount = ShiftSale.get_total_member_discount(@shift) + @total_dinein = ShiftSale.get_total_dinein(@shift).total_dinein_amount + @total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount + # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::CashierStationPrinter.new(print_settings) - printer.print_close_cashier(print_settings,cashier_terminal,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount) + printer.print_close_cashier(print_settings,cashier_terminal,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway) end end Employee.logout(session[:session_token]) @@ -102,8 +105,7 @@ class Origami::ShiftsController < BaseOrigamiController # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') - @total_member_discount = ShiftSale.get_total_member_discount(@shift) - + @total_member_discount = ShiftSale.get_total_member_discount(@shift) end end diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index fc79934d..400a0934 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -22,18 +22,18 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # end #Bill Receipt Print - def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount) + def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway) #Use CUPS service #Generate PDF #Print cashier = shift_sale.employee.name shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") - pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount) - + pdf = CloseCashierCustomerizePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway) filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" pdf.render_file filename self.print(filename, cashier_terminal.printer_name) end - #release_c1 + + end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 57816948..0127bd5c 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -135,6 +135,20 @@ class ShiftSale < ApplicationRecord end + def self.get_total_dinein(shift) + query = Sale.select("sum(sales.grand_total) as total_dinein_amount") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Dinein" and c.membership_id is null',shift.id) + .first() + end + + def self.get_total_takeway(shift) + query = Sale.select("sum(sales.grand_total) as total_takeway_amount") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Takeaway" and c.membership_id is null',shift.id) + .first() + end + def self.search(filter,from,to) if filter.blank? keyword = '' diff --git a/app/pdf/close_cashier_customerize_pdf.rb b/app/pdf/close_cashier_customerize_pdf.rb new file mode 100644 index 00000000..45834489 --- /dev/null +++ b/app/pdf/close_cashier_customerize_pdf.rb @@ -0,0 +1,433 @@ +class CloseCashierCustomerizePdf < 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,:text_width + + def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway) + self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width + self.page_height = printer_settings.page_height + self.margin = 5 + self.price_width = 60 + self.qty_width = 20 + self.total_width = 40 + self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) + self.item_height = 15 + self.item_description_width = (self.page_width-20) / 2 + self.label_width = 100 + + self.text_width = (self.page_width - 80) - self.price_width / 3 + # @item_width = self.page_width.to_i / 2 + # @qty_width = @item_width.to_i / 3 + # @double = @qty_width * 1.3 + # @half_qty = @qty_width / 2 + #setting page margin and width + super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + + # db font setup + if printer_settings.font != "" + font_families.update("#{printer_settings.font}" => { + :normal => "public/fonts/#{printer_settings.font}.ttf", + :italic => "public/fonts/#{printer_settings.font}.ttf", + :bold => "public/fonts/#{printer_settings.font}.ttf", + :bold_italic => "public/fonts/#{printer_settings.font}.ttf" + }) + + font "#{printer_settings.font}" + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + end + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + self.header_font_size = 10 + self.item_font_size = 8 + + #precision checked + if printer_settings.precision.to_i > 2 + printer_settings.precision = 2 + end + #check delimiter + if printer_settings.delimiter + delimiter = "," + else + delimiter = "" + end + + header( shop_details) + + stroke_horizontal_rule + + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_dinein,total_takeway) + end + + def header (shop_details) + move_down 7 + text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center + move_down 5 + text "#{shop_details.address}", :size => self.item_font_size,:align => :center + # move_down self.item_height + move_down 5 + text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center + move_down 5 + + stroke_horizontal_rule + end + + def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_dinein,total_takeway) + move_down 7 + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Cashier : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.employee.name}" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Cashier Station : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.cashier_terminal.name}" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Opening Date : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.shift_started_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Closing Date : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Opening Float : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Closing Float : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + end + + + move_down 10 + + y_position = cursor + bounding_box([0,y_position], :width =>self.page_width - 10, :height => 20) do + text "Shift Sale Summary", :size => self.header_font_size, :align => :center + end + move_down 10 + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Received Amount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Cash In :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Cash Out :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + move_down -5 + stroke_horizontal_rule + move_down 7 + + @total_grand_total = shift_sale.grand_total + @overall + @total_foc + shift_sale.total_void + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Grand Total :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Discount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total FOC :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Void :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "(#{shift_sale.total_void})", :size => self.item_font_size, :align => :right + end + + move_down -5 + stroke_horizontal_rule + move_down 7 + + @total_foc = 0 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Cash Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Credit Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + end + #start other payment details + if shift_sale.other_sales > 0 + other_payment.each do |other| + @total_foc = other.foc_amount.round(2) + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "MPU Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "VISA Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Master Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "JCB Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Reedem Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + end + else + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Other Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Rounding Adjustments :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Gross Sale :", :style => :bold, :size => self.header_font_size - 1, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + end + + # end other payment details + move_down -5 + stroke_horizontal_rule + move_down 7 + + # start Dinein and Takeaway + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Dinein :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(total_dinein, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Takeaway :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(total_takeway, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + + end + # stop Dinein and Takeaway + move_down -5 + stroke_horizontal_rule + move_down 7 + + #start service charges and commercial tax + sale_taxes.each do |tax| + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Taxes :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + end + #end for service charges and commercial tax +#COMMENTED FOR NO NEED AND NOT CORRECT WHEN OTHER CHARGES + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # text "Total Sale :", :size => self.item_font_size, :align => :right + # end + # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + # text "#{shift_sale.total_revenue}", :size => self.item_font_size, :align => :right + # end + + move_down -5 + stroke_horizontal_rule + move_down 7 + #start total amount by Account Like Food / Beverage /.. + total_discount_by_account.each do |amount| + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + end + end + #end total amount by Account + + if total_member_discount[0].member_discount.present? + @member_discount = total_member_discount[0].member_discount rescue 0.0 + @overall = shift_sale.total_discounts - @member_discount + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Member Discount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + else + @overall = shift_sale.total_discounts + end + + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # text "Grand Total :", :size => self.item_font_size, :align => :right + # end + # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right + # end + + + #start total amount by Account Like Food / Beverage /.. + total_amount_by_account.each do |amount| + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + end + end + #end total amount by Account + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Dine-in Count :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.dining_count}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Takeaway Count :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.takeaway_count}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Receipts :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.total_receipt}", :size => self.item_font_size, :align => :right + end + + move_down 5 + stroke_horizontal_rule + move_down 5 + move_down 5 + end +end + diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 35248b97..7bee4ed3 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -234,12 +234,14 @@ class CloseCashierPdf < Prawn::Document text "Rounding Adjustments :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_with_precision(shift_sale.total_dinein, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Total :", :style => :bold, :size => self.header_font_size - 1, :align => :right + text "Gross Sale :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right From 5b354299bbd5f84b61138c2a4380bfa3a52371ee Mon Sep 17 00:00:00 2001 From: Jueli Moon Aung Date: Fri, 16 Feb 2018 03:04:30 +0000 Subject: [PATCH 07/98] puma.rb.production edited by julian --- config/puma.rb.production | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config/puma.rb.production b/config/puma.rb.production index 4953a9b0..e88031af 100755 --- a/config/puma.rb.production +++ b/config/puma.rb.production @@ -1,7 +1,6 @@ -application_path = '/home/superuser/Application/production/sxrestaurant' +application_path = '/home/superuser/Application/sxrestaurant' directory application_path -environment ENV.fetch("RAILS_ENV") { "development" } -daemonize true +environment ENV.fetch("RAILS_ENV") { "production" } pidfile "#{application_path}/tmp/puma/pid" state_path "#{application_path}/tmp/puma/state" stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log" From cf7da9f25ce629e8517393aeda859d0bacbba6f6 Mon Sep 17 00:00:00 2001 From: Jueli Moon Aung Date: Fri, 16 Feb 2018 03:05:10 +0000 Subject: [PATCH 08/98] secrets.yml edited online by julian --- config/secrets.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/secrets.yml b/config/secrets.yml index a0220639..73e4fc37 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -24,7 +24,7 @@ test: # instead read values from the environment. production: secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22 - sx_provision_url: connect.smartsales.asia/api #192.168.1.147:3002/api + sx_provision_url: connect.smartsales.dev/api #192.168.1.147:3002/api server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L From dc5cd84f5cf6b98b4262a6e2c2e385be520a3663 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 19 Feb 2018 13:46:08 +0630 Subject: [PATCH 09/98] show cashier dashboard view --- app/controllers/application_controller.rb | 2 + app/controllers/home_controller.rb | 36 +-- app/models/sale.rb | 349 +++++++++++++++++++--- app/views/home/dashboard.html.erb | 31 +- config/locales/en.yml | 1 + config/locales/mm.yml | 1 + 6 files changed, 351 insertions(+), 69 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e66d7700..eaf89c34 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -89,6 +89,8 @@ class ApplicationController < ActionController::Base end def current_user + puts "session" + puts session[:session_token] @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 25fb0d70..db843aca 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -77,42 +77,42 @@ class HomeController < ApplicationController .sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)') @inventories = StockJournal.inventory_balances(today).sum(:balance) - @total_sale = Sale.total_sale(today) - @total_count = Sale.total_count(today) - @total_card = Sale.total_card_sale(today) - @total_credit = Sale.credit_payment(today) + @total_sale = Sale.total_sale(today,current_user) + @total_count = Sale.total_count(today,current_user) + @total_card = Sale.total_card_sale(today,current_user) + @total_credit = Sale.credit_payment(today,current_user) @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(today) + @total_payment_methods = Sale.total_payment_methods(today,current_user) @total_payment_methods.each do |payment| if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" - pay = Sale.payment_sale('card', today) + pay = Sale.payment_sale('card', today, current_user) @sale_data.push({'card' => pay.payment_amount}) else - pay = Sale.payment_sale(payment.payment_method, today) + pay = Sale.payment_sale(payment.payment_method, today, current_user) @sale_data.push({payment.payment_method => pay.payment_amount}) end end - @summ_sale = Sale.summary_sale_receipt(today) - @total_customer = Sale.total_customer(today) - @total_dinein = Sale.total_dinein(today) - @total_takeaway = Sale.total_takeaway(today) - @total_other_customer = Sale.total_other_customer(today) - @total_membership = Sale.total_membership(today) + @summ_sale = Sale.summary_sale_receipt(today,current_user) + @total_customer = Sale.total_customer(today,current_user) + @total_dinein = Sale.total_dinein(today,current_user) + @total_takeaway = Sale.total_takeaway(today,current_user) + @total_other_customer = Sale.total_other_customer(today,current_user) + @total_membership = Sale.total_membership(today,current_user) - @total_order = Sale.total_order(today) - @total_accounts = Sale.total_account(today) + @total_order = Sale.total_order(today,current_user) + @total_accounts = Sale.total_account(today,current_user) @account_data = Array.new @total_accounts.each do |account| - acc = Sale.account_data(account.account_id, today) + acc = Sale.account_data(account.account_id, today,current_user) if !acc.nil? @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end end - @top_items = Sale.top_items(today) - @total_foc_items = Sale.total_foc_items(today) + @top_items = Sale.top_items(today,current_user) + @total_foc_items = Sale.total_foc_items(today,current_user) # get printer info @print_settings = PrintSetting.get_precision_delimiter() diff --git a/app/models/sale.rb b/app/models/sale.rb index efdc8d30..3c97dbf8 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1088,60 +1088,158 @@ end .order("e.name") end - def self.total_sale(today) - total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total") - + def self.total_sale(today,current_user=nil) + if current_user.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total") + else + if current_user.role == 'administrator' + total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) + .sum("grand_total") + end + end + end end - def self.total_count(today) - total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count + def self.total_count(today,current_user=nil) + if current_user.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count + else + if current_user.role == 'administrator' + total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id = ?',today,shift.id).count + end + end + end end - def self.total_card_sale(today) - payment_type = " and payment_method = 'mpu' or payment_method = 'visa' or payment_method = 'master' or payment_method = 'jcb' or payment_method = 'unionpay' " - # query = Sale.select("SUM(tax_payable_amount) AS st_amount,tax_name") - # .where('sale_status = "completed" #{payment_type} and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) - # .joins("join sale_payments on sale_id = sales.sale_id") - # .group("sales.sale_id") - - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) + def self.total_card_sale(today,current_user=nil) + if current_user.nil? + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") - + else + if current_user.role == 'administrator' + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and shift_sale_id=?',today,shift.id) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + end + end + end end - def self.credit_payment(today) - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today) + def self.credit_payment(today,current_user=nil) + if current_user.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") + else + if current_user.role == 'administrator' + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ? and s.shift_sale_id=?',today,shift.id) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + end + end + end end - def self.summary_sale_receipt(today) - query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + def self.summary_sale_receipt(today,current_user=nil) + if current_user.nil? + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) .first() + else + if current_user.role == 'administrator' + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) + .first() + end + end + end end - def self.total_payment_methods(today) - query = Sale.select("distinct sp.payment_method") + def self.total_payment_methods(today,current_user=nil) + if current_user.nil? + query = Sale.select("distinct sp.payment_method") .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + if current_user.role == 'administrator' + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + end + end + end end - def self.payment_sale(payment_method, today) - query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + def self.payment_sale(payment_method, today, current_user=nil) + if current_user.nil? + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) else query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) end query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + else + if current_user.role == 'administrator' + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and sales.shift_sale_id=?',today,shift.id) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + end + end + end end - def self.total_customer(today) - dinein_cnt = self.total_dinein(today) - takeaway_cnt = self.total_takeaway(today) - membership_cnt = self.total_membership(today) + def self.total_customer(today,current_user=nil) + dinein_cnt = self.total_dinein(today,current_user) + takeaway_cnt = self.total_takeaway(today,current_user) + membership_cnt = self.total_membership(today,current_user) total_cus = 0 if !dinein_cnt.nil? || !takeaway_cnt.nil? || !membership_cnt.nil? @@ -1151,69 +1249,226 @@ end return total_cus end - def self.total_dinein(today) - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + def self.total_dinein(today,current_user=nil) + if current_user.nil? + query = Sale.select("count(sales.customer_id) as total_dinein_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + .first() + end + end + end end - def self.total_takeaway(today) - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) - .first() + def self.total_takeaway(today,current_user=nil) + if current_user.nil? + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + .first() + end + end + end end - def self.total_membership(today) - query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + def self.total_membership(today,current_user=nil) + if current_user.nil? + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today) .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',today,shift.id) + .first() + end + end + end end - def self.total_other_customer(today) - query = Sale.select("count(sales.customer_id) as total_cus") + def self.total_other_customer(today,current_user=nil) + if current_user.nil? + query = Sale.select("count(sales.customer_id) as total_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(sales.customer_id) as total_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(sales.customer_id) as total_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + .first() + end + end + end end - def self.total_order(today) - query = Sale.select("count(distinct a.order_id) as total_order") + def self.total_order(today,current_user=nil) + if current_user.nil? + query = Sale.select("count(distinct a.order_id) as total_order") .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") .joins("JOIN orders as b ON b.order_id = a.order_id") .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(distinct a.order_id) as total_order") + .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") + .joins("JOIN orders as b ON b.order_id = a.order_id") + .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(distinct a.order_id) as total_order") + .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") + .joins("JOIN orders as b ON b.order_id = a.order_id") + .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) + .first() + end + end + end end - def self.total_account(today) - query = Sale.select("distinct b.id as account_id, b.title as title") + def self.total_account(today,current_user=nil) + if current_user.nil? + query = Sale.select("distinct b.id as account_id, b.title as title") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_id") .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + else + if current_user.role == 'administrator' + query = Sale.select("distinct b.id as account_id, b.title as title") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .joins("JOIN accounts as b ON b.id = a.account_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("distinct b.id as account_id, b.title as title") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .joins("JOIN accounts as b ON b.id = a.account_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) + end + end + end end - def self.account_data(account_id, today) - query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") + def self.account_data(account_id, today, current_user=nil) + if current_user.nil? + query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) + .first() + end + end + end end - def self.top_items(today) - query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") + def self.top_items(today,current_user=nil) + if current_user.nil? + query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .group("a.product_code") .order("SUM(a.qty) DESC") .first() + else + if current_user.role == 'administrator' + query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .group("a.product_code") + .order("SUM(a.qty) DESC") + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) + .group("a.product_code") + .order("SUM(a.qty) DESC") + .first() + end + end + end end - def self.total_foc_items(today) - query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + def self.total_foc_items(today,current_user=nil) + if current_user.nil? + query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .sum("a.qty") + else + if current_user.role == 'administrator' + query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .sum("a.qty") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) + .sum("a.qty") + end + end + end end #card sale trans data diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 104c4c67..4056e064 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -1,6 +1,7 @@
-

<%= t :dashboard %>

+ +

<%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %>

<% if @print_settings.precision.to_i > 0 precision = @print_settings.precision @@ -14,6 +15,7 @@ delimiter = "" end %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
@@ -62,11 +64,12 @@
+ <% end %> - <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
+ <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
@@ -122,10 +125,18 @@
-
+ <% end %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'cashier' %> <% if !@summ_sale.nil? %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' %> +
+ <% else %> +
+
+
+ <% end %>
<%= t :sale %>
@@ -184,11 +195,17 @@
+ <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
<% end %> + <% end %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
+ <% else %> +
+ <% end %>
<%= t :customer %>
@@ -227,10 +244,16 @@
+ <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
+ <% end %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
+ <% else %> +
+ <% end %>
<%= t("views.right_panel.detail.order") %>
@@ -274,6 +297,6 @@
+ <% end %>
- <% end %>
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index d4dc8005..6d562366 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -71,6 +71,7 @@ en: bottom: "Bottom" payment: "Payment" backend: "Backend" + date_time: "DateTime" views: btn: diff --git a/config/locales/mm.yml b/config/locales/mm.yml index 2d35b1bf..06756c1c 100755 --- a/config/locales/mm.yml +++ b/config/locales/mm.yml @@ -66,6 +66,7 @@ mm: bottom: "အရောင်းအနဲဆုံး" payment: "ငွေပေးချေမှု" backend: "Backend" + date_time: "DateTime" views: btn: From d134e3f67d8393bd4cbd90b3ca04edc300eef98a Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 19 Feb 2018 14:43:34 +0630 Subject: [PATCH 10/98] add survey for waiter --- app/models/sale.rb | 4 ++-- app/views/home/dashboard.html.erb | 10 ++++++++-- app/views/origami/home/show.html.erb | 4 +++- app/views/origami/rooms/show.html.erb | 4 ++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 3c97dbf8..af2df171 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1060,7 +1060,7 @@ end .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ "and payment_status='paid' and sale_status= 'completed'") .group('mi.name') - .order("SUM(i.qty) DESC").limit(10) + .order("SUM(i.qty) DESC").limit(20) end def self.bottom_products(today) @@ -1070,7 +1070,7 @@ end .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ "and payment_status='paid' and sale_status= 'completed'") .group('mi.name') - .order("SUM(i.qty) ASC").limit(10) + .order("SUM(i.qty) ASC").limit(20) end def self.hourly_sales(today) diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 4056e064..f935522b 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -15,7 +15,6 @@ delimiter = "" end %> - <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
@@ -64,10 +63,17 @@
- <% end %> + +
+
+ +
+
+ +
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 6e1f7128..386a142f 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -411,8 +411,10 @@ <%= t("views.btn.back") %> - <% if current_login_employee.role != "waiter" %> + <% if current_login_employee.role == "administrator" || current_login_employee.role == "manager" || current_login_employee.role == "supervisor" || current_login_employee.role == "cashier" || current_login_employee.role == "waiter" %> + <% end %> + <% if current_login_employee.role != "waiter" %> <% if @dining.status != "available" %> <% if @status_order == 'order' && @status_sale != 'sale' %> diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 17674fff..de774e2b 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -382,7 +382,10 @@ + <% if current_login_employee.role == "administrator" || current_login_employee.role == "manager" || current_login_employee.role == "supervisor" || current_login_employee.role == "cashier" || current_login_employee.role == "waiter" %> + <% end %> + <% if current_login_employee.role != "waiter" %> <% if @room.bookings.length >= 1 %> <% if @status_order == 'order' && @status_sale != 'sale' %> @@ -453,6 +456,7 @@ <% end %> + <% end %>
From 9f2bab7187d4d7d854c1ebfcb886aa7d5377b08c Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 19 Feb 2018 14:49:46 +0630 Subject: [PATCH 11/98] check customer tax profiles in origami --- app/controllers/origami/home_controller.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 93a83be2..31fea079 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -88,14 +88,17 @@ class Origami::HomeController < BaseOrigamiController end @order_items.push(item) end - accounts = @customer.tax_profiles - puts accounts.to_json - puts "sssssssssss" - puts @customer.tax_profiles - @account_arr =[] - accounts.each do |acc| - account = TaxProfile.find(acc) - @account_arr.push(account) + @account_arr = Array.new + if @customer.tax_profiles + accounts = @customer.tax_profiles + puts accounts.to_json + puts "sssssssssss" + puts @customer.tax_profiles + @account_arr =[] + accounts.each do |acc| + account = TaxProfile.find(acc) + @account_arr.push(account) + end end end end From 521b4d897b82ff19f352bc3da1296f3f72c40ddd Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 19 Feb 2018 15:43:27 +0630 Subject: [PATCH 12/98] change migration file --- app/controllers/application_controller.rb | 10 +++++----- app/controllers/home_controller.rb | 19 +++++++++++++++++++ app/views/home/dashboard.html.erb | 16 +++++++++++++--- db/migrate/20170403155230_create_employees.rb | 1 + db/migrate/20170622050926_create_customers.rb | 1 + .../20170825090115_create_commissioners.rb | 1 + ...80213050551_add_image_path_to_employees.rb | 9 --------- ...80213050631_add_image_path_to_customers.rb | 9 --------- ...3052206_add_image_path_to_commissioners.rb | 9 --------- 9 files changed, 40 insertions(+), 35 deletions(-) delete mode 100644 db/migrate/20180213050551_add_image_path_to_employees.rb delete mode 100644 db/migrate/20180213050631_add_image_path_to_customers.rb delete mode 100644 db/migrate/20180213052206_add_image_path_to_commissioners.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 67f6cb46..eaf89c34 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -38,11 +38,11 @@ class ApplicationController < ActionController::Base end else # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index db843aca..99c6d5f6 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -62,6 +62,9 @@ class HomeController < ApplicationController end def dashboard + # puts "date range =>" + # puts get_date_range_from_params + @shop = Shop.first today = DateTime.now.strftime('%Y-%m-%d') @@ -162,4 +165,20 @@ class HomeController < ApplicationController redirect_to reports_dailysale_index_path end end + + def get_date_range_from_params + from = params[:from] + to = params[:to] + + if from.present? && to.present? + f_date = DateTime.parse(from) + t_date = DateTime.parse(to) + f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) + t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) + from = f_time.beginning_of_day.utc.getlocal + to = t_time.end_of_day.utc.getlocal + end + + return from, to + end end diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index f935522b..d1a13775 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -67,11 +67,21 @@ -
-
- +
diff --git a/db/migrate/20170403155230_create_employees.rb b/db/migrate/20170403155230_create_employees.rb index c4bf65ac..4270b265 100755 --- a/db/migrate/20170403155230_create_employees.rb +++ b/db/migrate/20170403155230_create_employees.rb @@ -9,6 +9,7 @@ class CreateEmployees < ActiveRecord::Migration[5.1] t.datetime :session_expiry t.datetime :session_last_login t.string :created_by + t.string :image_path t.timestamps end end diff --git a/db/migrate/20170622050926_create_customers.rb b/db/migrate/20170622050926_create_customers.rb index cb370bc1..b01362fe 100755 --- a/db/migrate/20170622050926_create_customers.rb +++ b/db/migrate/20170622050926_create_customers.rb @@ -18,6 +18,7 @@ class CreateCustomers < ActiveRecord::Migration[5.1] t.string :membership_authentication_code t.string :customer_type, :default => "Dinein" t.json :tax_profiles + t.string :image_path end end end diff --git a/db/migrate/20170825090115_create_commissioners.rb b/db/migrate/20170825090115_create_commissioners.rb index 1794b5c7..a89920d5 100755 --- a/db/migrate/20170825090115_create_commissioners.rb +++ b/db/migrate/20170825090115_create_commissioners.rb @@ -9,6 +9,7 @@ class CreateCommissioners < ActiveRecord::Migration[5.1] t.datetime :joined_date t.datetime :resigned_date t.boolean :is_active, default: true + t.string :image_path t.timestamps end end diff --git a/db/migrate/20180213050551_add_image_path_to_employees.rb b/db/migrate/20180213050551_add_image_path_to_employees.rb deleted file mode 100644 index bb26e888..00000000 --- a/db/migrate/20180213050551_add_image_path_to_employees.rb +++ /dev/null @@ -1,9 +0,0 @@ -class AddImagePathToEmployees < ActiveRecord::Migration[5.1] - def change - add_column :employees, :image_path, :string - end - - def down - remove_column :image_path - end -end diff --git a/db/migrate/20180213050631_add_image_path_to_customers.rb b/db/migrate/20180213050631_add_image_path_to_customers.rb deleted file mode 100644 index 11eecdc0..00000000 --- a/db/migrate/20180213050631_add_image_path_to_customers.rb +++ /dev/null @@ -1,9 +0,0 @@ -class AddImagePathToCustomers < ActiveRecord::Migration[5.1] - def change - add_column :customers, :image_path, :string - end - - def down - remove_column :image_path - end -end diff --git a/db/migrate/20180213052206_add_image_path_to_commissioners.rb b/db/migrate/20180213052206_add_image_path_to_commissioners.rb deleted file mode 100644 index f61dce61..00000000 --- a/db/migrate/20180213052206_add_image_path_to_commissioners.rb +++ /dev/null @@ -1,9 +0,0 @@ -class AddImagePathToCommissioners < ActiveRecord::Migration[5.1] - def change - add_column :commissioners, :image_path, :string - end - - def down - remove_column :image_path - end -end From 4bfb5842bfb09c4727609a06056d76e3ac893d5e Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 20 Feb 2018 13:33:59 +0630 Subject: [PATCH 13/98] split bill process --- .../origami/payments_controller.rb | 14 ++++- app/controllers/origami/surveys_controller.rb | 59 +++++++++++++++---- app/pdf/receipt_bill_a5_pdf.rb | 2 +- app/pdf/receipt_bill_pdf.rb | 2 +- app/views/origami/payments/show.html.erb | 8 +++ app/views/origami/split_bill/index.html.erb | 20 ++++++- config/routes.rb | 1 + 7 files changed, 88 insertions(+), 18 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 82761dd1..28a82d83 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -186,9 +186,21 @@ class Origami::PaymentsController < BaseOrigamiController @table_no = '' @dining = '' - @shop = Shop::ShopDetail + @shop = Shop::ShopDetail #show shop info saleObj = Sale.find(sale_id) + + #total customer with individual total amount + survey = nil + @individual_total = Array.new + if !@sale_data.nil? + survey = Survey.find_by_receipt_no(@sale_data.receipt_no) + if !survey.nil? + per_person_amount = saleObj.grand_total.to_f / survey.total_customer.to_i + @individual_total.push({'total_customer' => survey.total_customer, 'per_person_amount' => per_person_amount.to_f }) + end + end + # rounding adjustment if @shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index 02ec9795..12d6d543 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -86,9 +86,10 @@ class Origami::SurveysController < BaseOrigamiController def create_survey if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id) - @type = params[:cashier_type] - @sale_id = params[:sale_id] - sale = Sale.find(@sale_id) + @type = params[:cashier_type] + @sale_id = params[:sale_id] + sale = Sale.find(@sale_id) + receipt_no = params[:receipt_no] if @type != "quick_service" dining_facility = DiningFacility.find(params[:dining_id]) @@ -102,27 +103,43 @@ class Origami::SurveysController < BaseOrigamiController shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_terminal_id,nil) if @type != "quick_service" - survey = Survey.find_by_dining_name(dining_facility.name) + survey = Survey.find_by_dining_name_and_receipt_no(dining_facility.name,receipt_no) else survey = nil end if survey.nil? - survey = Survey.new if @type != "quick_service" - survey.dining_name = dining_facility.name + survey = Survey.find_by_dining_name_and_receipt_no(dining_facility.name,nil) + if survey.nil? + survey = Survey.new + survey.dining_name = dining_facility.name + survey.receipt_no = params[:receipt_no] + survey.shift_id = shift_by_terminal.id + survey.created_by = current_user.name + survey.total_customer = params[:total_customer] + survey.total_amount = params[:total_amount] + survey.save! + else + survey.receipt_no = params[:receipt_no] + survey.total_customer = params[:total_customer] + survey.total_amount = params[:total_amount] + survey.save! + end + else + survey = Survey.new + survey.receipt_no = params[:receipt_no] + survey.shift_id = shift_by_terminal.id + survey.created_by = current_user.name + survey.total_customer = params[:total_customer] + survey.total_amount = params[:total_amount] + survey.save! end - - survey.receipt_no = params[:receipt_no] - survey.shift_id = shift_by_terminal.id - survey.created_by = current_user.name - survey.total_customer = params[:total_customer] - survey.total_amount = params[:total_amount] - survey.save! else survey.receipt_no = params[:receipt_no] survey.total_customer = params[:total_customer] + survey.total_amount = params[:total_amount] survey.save! end render :json => {status: true} @@ -131,6 +148,22 @@ class Origami::SurveysController < BaseOrigamiController end end + def get_survey + dining_id = params[:dining_id] + receipt_no = params[:receipt_no] + table = DiningFacility.find_by_id(dining_id) + survey = Survey.find_by_dining_name_and_receipt_no(table.name,receipt_no) + if survey.nil? + survey = Survey.find_by_dining_name_and_receipt_no(table.name,nil) + end + + if !survey.nil? + render :json => { status: true, survey: survey } + else + render :json => { status: false } + end + end + private # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 6125078b..5655cc38 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -484,7 +484,7 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([0,y_position], :width =>self.label_width) do move_down 15 - text "Total", :size => self.item_font_size,:align => :left + text "Total Amount", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 2f7fa0eb..64348fe8 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -493,7 +493,7 @@ class ReceiptBillPdf < Prawn::Document bounding_box([0,y_position], :width =>self.label_width) do move_down 15 - text "Total", :size => self.item_font_size,:align => :left + text "Total Amount", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 8c275785..9cb9f397 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -107,6 +107,14 @@ <%=@balance%> <% end %> + <% if !@individual_total.nil? %> + + + Individual amount for <%= @individual_total[0]['total_customer'] %> persons + + <%=@individual_total[0]['per_person_amount']%> + + <% end %>
diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb index f246e98c..a423f298 100755 --- a/app/views/origami/split_bill/index.html.erb +++ b/app/views/origami/split_bill/index.html.erb @@ -249,7 +249,7 @@ @@ -31,19 +38,38 @@
-
-   Receipt No: - <%= @sale.receipt_no rescue '' %> - -
-
- Date: <%= @sale.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>   -
+ + <% if @status == 'sale' %> +
+   Receipt No: + <%= @sale.receipt_no rescue '' %> +
+ <% else%> + +
+   Order No: + <%= @bookings.booking_orders[0].order_id rescue '' %> +
+ <% end%> + + + <% if @status == 'sale' %> +
+ Date: <%= @sale.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>   +
+ <% else%> +
+ Date: <%= @order.created_at.strftime("%I:%M %p") rescue '-'%>   +
+ <% end%>
-   Customer : <%= @sale.customer.name rescue "-" %> - + <% if @status == 'sale' %> +   Customer : <%= @sale.customer.name rescue "-" %> + <% else%> +   Customer : <%= @order.customer.name rescue "-" %> + <% end%>
@@ -58,55 +84,64 @@ - <% - sub_total = 0 + <% if @status == 'sale' %> + <% sub_total = 0 @sale.sale_items.each do |sale_item| - sub_total = sub_total + sale_item.price - %> - - <% #unless sale_item.price <= 0 %> - - <%= sale_item.product_name %> - <%= sale_item.qty %> - <%= sale_item.price %> - - <% - - #end - end - - %> + sub_total = sub_total + sale_item.price %> + + + <%= sale_item.product_name %> + <%= sale_item.qty %> + <%= sale_item.price %> + + <% end%> + <% else%> + <% sub_total = 0 + @order_items.each do |order_item| + sub_total = sub_total + order_item.price %> + + + <%= order_item.item_name %> + <%= order_item.qty %> + <%= order_item.price %> + + <% end%> + <% end%> +
@@ -115,8 +150,15 @@
+ <% if current_user.role != "waiter" || @status != "sale"%> - + <%end%> + <% if current_user.role != "waiter"%> + + <%end%> + <% if @status != "sale"%> + + <%end%>
@@ -135,7 +177,7 @@ $(document).ready(function(){ }); $('#addorder').on('click', function () { var table_id = "<%=@table_id%>"; - var booking_id = "<%=@booking%>"; + var booking_id = "<%=@bookings.booking_id%>"; if (table_id) { window.location.href = '/origami/quick_service/modify_order/' + table_id+"/"+$('#sale_id').val(); }else{ @@ -143,5 +185,23 @@ $(document).ready(function(){ } }); + // Bill Request + $('#request_bills').click(function () { + var order_id = $('#save_order_id').val(); + var ajax_url = "/origami/" + order_id + "/request_bills"; + $.ajax({ + type: "GET", + url: ajax_url, + // data: 'order_id='+ order_id, + success: function (result) { + if (!result.status) { + swal("Information!", result.error_message); + } + else { + location.reload(); + } + } + }); + }); }); From f559aa0f14bc0d7dca6bc2a76b7980248f701a09 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 26 Feb 2018 09:20:57 +0630 Subject: [PATCH 56/98] product sale query --- .../reports/product_sale_controller.rb | 70 +---- app/models/sale.rb | 54 +--- .../_shift_sale_report_filter.html.erb | 120 ------- app/views/reports/product_sale/index.html.erb | 294 ++++-------------- app/views/reports/product_sale/index.xls.erb | 177 ++--------- 5 files changed, 119 insertions(+), 596 deletions(-) delete mode 100755 app/views/reports/product_sale/_shift_sale_report_filter.html.erb diff --git a/app/controllers/reports/product_sale_controller.rb b/app/controllers/reports/product_sale_controller.rb index 0061818a..afb4b537 100644 --- a/app/controllers/reports/product_sale_controller.rb +++ b/app/controllers/reports/product_sale_controller.rb @@ -2,79 +2,19 @@ class Reports::ProductSaleController < BaseReportController authorize_resource :class => false def index - from, to = get_date_range_from_params - shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + order_by = 'desc' + if !params[:order_by].nil? + order_by = params[:order_by] + end - shift = '' - if params[:shift_name].to_i != 0 - shift_sale = ShiftSale.find(params[:shift_name]) - if to.blank? - shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) - else - - shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) - end - end - @sale_data, @grand_total = Sale.get_by_items(shift_sale_range,shift, from, to) - - @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) - - @account_cate_count = Hash.new {|hash, key| hash[key] = 0} - - - @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} - - @menu_cate_count = Hash.new {|hash, key| hash[key] = 0} - @sale_data.each {|cate| @menu_cate_count[cate.account_id] += 1} - - - @totalByAccount = Hash.new {|hash, key| hash[key] = 0} - @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} - - @from = from - @to = to + @sale_data = Sale.get_menu_item_query(order_by) # get printer info @print_settings = PrintSetting.get_precision_delimiter() - if shift.present? - shift.each do |sh| - @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") - @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") - @shift_data = sh - end - end - respond_to do |format| format.html format.xls end end - - # def show - # from, to, report_type = get_date_range_from_params - - # @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) - - # date_arr = Array.new - # @sale_data.each do |sale| - # local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") - # local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") - # opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc - # closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc - # shift_id = sale.id.nil? ? '-' : sale.id - # str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} - # date_arr.push(str) - # end - - # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} - # @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} - - # out = {:status => 'ok', :message => date_arr} - - # respond_to do |format| - # format.json { render json: out } - # end - # end - end diff --git a/app/models/sale.rb b/app/models/sale.rb index 54806964..4167d549 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -861,45 +861,23 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status) end #product sale report query -def self.get_menu_item_query() - query = MenuItem.select("acc.id as account_id, acc.title as account_name, - i.item_instance_code as item_code, " + - "i.qty as qty," + - "i.product_name as product_name, +def self.get_menu_item_query(order_by) + query = MenuItem.unscoped.select("acc.id as account_id, + acc.title as account_name, + mii.item_instance_code as item_code, " + + "(CASE WHEN si.qty > 0 THEN SUM(si.qty) ELSE 0 END) as total_item," + + "(CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END) as unit_price," + + "(CASE WHEN (si.qty * si.unit_price) > 0 THEN (si.qty * si.unit_price) ELSE 0 END) as grand_total," + + "mii.price as unit_price, menu_items.name as product_name, mc.name as" + - " menu_category_name,mc.id as menu_category_id ") - - query = query.joins(" LEFT JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" + - " LEFT JOIN menu_items mi ON mi.id = mii.menu_item_id" + - " LEFT JOIN menu_categories mc ON mc.id = mi.menu_category_id" + - " LEFT JOIN accounts acc ON acc.id = mi.account_id") - query = query.group("acc.title,mi.account_id,mi.menu_category_id,mi.name,mii.price") - .order("acc.title desc, mi.account_id desc, mi.menu_category_id desc, mii.price asc") -end - -def self.get_by_items(shift_sale_range, shift, from, to) - query = self.get_menu_item_query() - - puts "query" - total_grand_total = 0 - - # if shift.present? - # query = query.where("sales.shift_sale_id IN (?)",shift.to_a) - - # # total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f - - # ### => get all sales range in shift_sales - # elsif shift_sale_range.present? - # query = query.where("sales.shift_sale_id IN (?)",shift_sale_range.to_a) - - # # total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f - - # else - # query = query.where("sales.receipt_date between ? and ?",from,to) - # # total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f - # end - - return query, total_grand_total + " menu_category_name,mc.id as menu_category_id, si.remark as status_type, si.price as price ") + .joins(" LEFT JOIN menu_item_instances mii ON menu_items.id = mii.menu_item_id" + + " LEFT JOIN menu_categories mc ON mc.id = menu_items.menu_category_id" + + " LEFT JOIN accounts acc ON acc.id = menu_items.account_id" + + " LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" + + " LEFT JOIN sales s ON s.sale_id = si.sale_id") + .group("mc.id, menu_items.name, si.qty, (CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END)") + .order("si.qty #{order_by}, menu_items.menu_category_id desc") end #product sale report query diff --git a/app/views/reports/product_sale/_shift_sale_report_filter.html.erb b/app/views/reports/product_sale/_shift_sale_report_filter.html.erb deleted file mode 100755 index 88f26c1f..00000000 --- a/app/views/reports/product_sale/_shift_sale_report_filter.html.erb +++ /dev/null @@ -1,120 +0,0 @@ -
- <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> - <% if period_type != false %> -
-
- - -
- -
- - - -
-
- - -
-
- - -
-
-
- -
-
- <% end %> - - <% end %> -
- - diff --git a/app/views/reports/product_sale/index.html.erb b/app/views/reports/product_sale/index.html.erb index 12e1dfe1..ab3136a3 100644 --- a/app/views/reports/product_sale/index.html.erb +++ b/app/views/reports/product_sale/index.html.erb @@ -9,31 +9,25 @@
- <%= render :partial=>'shift_sale_report_filter', - :locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_product_sale_index_path} %> - -
-
+
+
+ + +
+
+
- - - - <% if @shift_from %> - - <% if @shift_data.employee %> - <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> - - - <% end %> @@ -41,7 +35,7 @@ - + @@ -58,114 +52,48 @@ end %> <% unless @sale_data.blank? %> - <% acc_arr = Array.new %> - <% cate_arr = Array.new %> + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> - <% sub_qty = 0 %> - <% sub_total = 0 %> - <% other_sub_total = 0 %> - <% count = 0 %> - <% total_price = 0 %> - <% cate_count = 0 %> - <% acc_count = 0 %> - <% grand_total = 0 %> - <% total_qty = 0 %> - <% total_amount = 0 %> - <% discount = 0 %> - <% total_item_foc = 0 %> - <% total_item_dis = 0.0 %> - <% total_tax = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> - <% @sale_data.each do |sale| %> - - <% if sale.status_type != "Discount" && sale.status_type != "foc" - total_qty += sale.total_item - end %> - <% if sale.status_type == "foc" && sale.price > 0 - total_qty += sale.total_item - end %> - - <% if sale.status_type == "foc" && sale.grand_total < 0 - total_item_foc += sale.grand_total*(-1) - end %> - - <% if sale.status_type == "Discount" && sale.grand_total < 0 - total_item_dis += sale.grand_total*(-1) - end %> - - <% if !acc_arr.include?(sale.account_id) %> - - - - - - - <% acc_arr.push(sale.account_id) %> - <% end %> - - - <% if !cate_arr.include?(sale.menu_category_id) %> - - <% cate_arr.push(sale.menu_category_id) %> - <% else %> - - <% end %> - - - - - - - - - <% @menu_cate_count.each do |key,value| %> - <% if sale.account_id == key %> - <% count = count + 1 %> - <% sub_total += sale.grand_total %> - <% #sub_qty += sale.total_item %> - <% if sale.status_type!="Discount" && (!sale.product_name.include? "FOC") - sub_qty += sale.total_item + <% @sale_data.each do |sale| %> + <% if sale.status_type != "Discount" && sale.status_type != "foc" + total_qty += sale.total_item + grand_total += sale.grand_total + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + grand_total += sale.grand_total end %> - <% if count == value %> - - - - - - - - <% sub_total = 0.0%> - <% sub_qty = 0 %> - <% count = 0%> - <% end %> - <% end %> - <% end %> - - <% end %> - - - - - - - - - <% end %> - - + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + + + + + + + <% end %> - - - + + + + + + + <% end %>
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
<%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
  <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.product") %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %><%= t("views.right_panel.detail.total") %>
<%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> - <% @totalByAccount.each do |account, total| %> - <% if sale.account_id == account %> - <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> - <% grand_total += total %> - <% end %> - <% end %> -
 <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%>
 <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
 <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %>
 Net Amount<%= number_with_precision(grand_total.to_f - @discount_data.to_f , precision:precision.to_i,delimiter:delimiter)%>Total<%= total_qty %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %>
@@ -175,118 +103,26 @@
\ No newline at end of file diff --git a/app/views/reports/product_sale/index.xls.erb b/app/views/reports/product_sale/index.xls.erb index f97edbb8..7123588c 100755 --- a/app/views/reports/product_sale/index.xls.erb +++ b/app/views/reports/product_sale/index.xls.erb @@ -5,17 +5,6 @@
- - - - <% if @shift_from %> - - <% if @shift_data.employee %> - <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> - - - <% end %> @@ -23,149 +12,49 @@ - + <% unless @sale_data.blank? %> - <% acc_arr = Array.new %> - <% cate_arr = Array.new %> + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + <% grand_total = 0 %> + <% total_qty = 0 %> - <% sub_total = 0 %> - <% other_sub_total = 0 %> - <% count = 0 %> - <% total_price = 0 %> - <% cate_count = 0 %> - <% acc_count = 0 %> - <% grand_total = 0 %> - <% total_qty = 0 %> - <% total_amount = 0 %> - <% discount = 0 %> - <% total_item_foc = 0 %> - <% total_item_dis = 0 %> + <% @sale_data.each do |sale| %> + <% if sale.status_type != "Discount" && sale.status_type != "foc" + total_qty += sale.total_item + grand_total += sale.grand_total + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + grand_total += sale.grand_total + end %> - <% @sale_data.each do |sale| %> - - <% if sale.total_item > 0 - total_qty += sale.total_item - end %> - - <% if !acc_arr.include?(sale.account_id) %> - - - - + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + + + - <% acc_arr.push(sale.account_id) %> <% end %> - - <% if !cate_arr.include?(sale.menu_category_id) %> - - <% cate_arr.push(sale.menu_category_id) %> - <% else %> - - <% end %> - - - - - - - - <% @menu_cate_count.each do |key,value| %> - <% if sale.menu_category_id == key %> - - <% count = count + 1 %> - <% sub_total += sale.grand_total %> - <% if count == value %> - - - - - - <% if sale.status_type === "foc" - total_item_foc += sale.grand_total - end %> - - <% if sale.status_type === "Discount" - total_item_dis += sale.grand_total - end %> - <% sub_total = 0.0%> - <% count = 0%> - <% end %> - <% end %> - <% end %> - - <% end %> - - - - - - - <% @other_charges.each do |other| %> - <% if other.total_item > 0 - total_qty += other.total_item - end %> - <% grand_total +=other.grand_total%> - - - - - - - - - - - - <% other_sub_total += other.grand_total %> - - <% end %> - - - - - - - - - - - - - - <% end %> - - - - - - - - - - - - - - - - - - - - - + + + + + + + <% end %>
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
<%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
  <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.product") %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %><%= t("views.right_panel.detail.total") %>
<%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> - <% @totalByAccount.each do |account, total| %> - <% if sale.account_id == account %> - <%= total %> - <% grand_total += total %> - <% end %> - <% end %> -  <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.unit_price rescue '-' %><%= sale.grand_total rescue '-' %>
 <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.unit_price rescue '-' %><%= sale.grand_total rescue '-' %>
 <%= t("views.right_panel.detail.sub_total") %><%= sub_total %>
Other Charges 
 Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %><%= other.unit_price rescue '-' %><%= other.grand_total rescue '-' %>
 <%= t("views.right_panel.detail.sub_total") %><%= other_sub_total %>
 <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.net_amount") %><%= grand_total%>
 <%= t("views.right_panel.detail.foc_item") %> <%= t("views.right_panel.detail.amount") %><%= total_item_foc %>
 <%= t("views.right_panel.detail.item_discount") %> <%= t("views.right_panel.detail.amount") %><%= total_item_dis %>
 <%= t("views.right_panel.detail.foc_sales") %><%= @foc_data %>
 <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %><%= @discount_data %>
Total<%= total_qty %><%= grand_total rescue '-' %>
From a0b34e80844bafbc6b48ea6af932d410526dde2f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 26 Feb 2018 09:33:38 +0630 Subject: [PATCH 57/98] update scroll for order --- app/views/origami/addorders/detail.html.erb | 88 +++++++++++---------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index c2bd6deb..0c3e7bb5 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -84,48 +84,56 @@ <%end %>
+ + +
-
From 8b064a442855cdf401c35c58d6606e657e83fcc8 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 26 Feb 2018 10:01:35 +0630 Subject: [PATCH 58/98] change assigned item id to order item id --- app/controllers/oqs/edit_controller.rb | 9 ++- app/controllers/origami/home_controller.rb | 10 ++-- app/views/origami/home/show.html.erb | 69 +++++----------------- 3 files changed, 25 insertions(+), 63 deletions(-) diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index 52ebdd2c..ea2e6662 100755 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -3,12 +3,15 @@ class Oqs::EditController < BaseOqsController assigned_item_id = params[:id] @link_type = params[:type] @dining_type = nil - if params[:type] != 'oqs' + if params[:type] == 'oqs' + assigned_item = AssignedOrderItem.find(assigned_item_id) + @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.instance_code }'") + else + assigned_item = OrderItem.find(assigned_item_id) dining = DiningFacility.find_by_id(params[:type]) @dining_type = dining.type + @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.item_instance_code }'") end - assigned_item = AssignedOrderItem.find(assigned_item_id) - @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.instance_code }'"); end def update diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index eedbfdfc..c33a02fa 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -62,7 +62,7 @@ class Origami::HomeController < BaseOrigamiController @dining.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new - @assigned_order_items = Array.new + # @assigned_order_items = Array.new if booking.booking_orders.empty? @booking = booking else @@ -85,10 +85,10 @@ class Origami::HomeController < BaseOrigamiController item.set_menu_items = arr_instance_item_sets end @order_items.push(item) - assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id) - if !assigned_order_items.nil? - @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id}) - end + # assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id) + # if !assigned_order_items.nil? + # @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id}) + # end end accounts = @customer.tax_profiles puts accounts.to_json diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index d50d5182..19223467 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -288,26 +288,7 @@ sub_total = sub_total + (order_item.price * order_item.qty) # unless order_item.price == 0 %> - <% if !@assigned_order_items.nil? %> - <% @assigned_order_items.each do |assigned_order_item| %> - <% if assigned_order_item.include? (order_item.order_items_id) %> - - <%= count %> - - <%= order_item.item_name %> - <% if !order_item.set_menu_items.nil? - order_item.set_menu_items.each do |item_instance| %> -
<%= item_instance %> - <% end - end %> - - <%= order_item.qty %> - <%= order_item.qty*order_item.price %> - - <% end %> - <% end %> - <% else %> - + <%= count %> <%= order_item.item_name %> @@ -320,7 +301,6 @@ <%= order_item.qty %> <%= order_item.qty*order_item.price %> - <% end %> <% # end @@ -387,40 +367,19 @@ @order_items.each do |order_item| count += 1 %> - <% if !@assigned_order_items.nil? %> - <% @assigned_order_items.each do |assigned_order_item| %> - <% if assigned_order_item.include? (order_item.order_items_id) %> - - <%= count %> - - <%= order_item.item_name %> - <% if !order_item.set_menu_items.nil? - order_item.set_menu_items.each do |item_instance| %> -
<%= item_instance %> - <% end - end %> - - <%= order_item.qty %> - <%= order_item.qty*order_item.price %> - - <% end %> - <% end %> - <% else %> - - <%= count %> - - <%= order_item.item_name %> - <% if !order_item.set_menu_items.nil? - order_item.set_menu_items.each do |item_instance| %> -
<%= item_instance %> - <% end - end %> - - <%= order_item.qty %> - <%= order_item.qty*order_item.price %> - - <% end %> - + + <%= count %> + + <%= order_item.item_name %> + <% if !order_item.set_menu_items.nil? + order_item.set_menu_items.each do |item_instance| %> +
<%= item_instance %> + <% end + end %> + + <%= order_item.qty %> + <%= order_item.qty*order_item.price %> + <% end %> From a76d0ddbcd721767e557130d8598778cfa5afbd6 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 26 Feb 2018 10:09:33 +0630 Subject: [PATCH 59/98] change assigned order item id to order item id in Origami/Room --- app/controllers/origami/rooms_controller.rb | 10 +-- app/views/origami/rooms/show.html.erb | 68 +++++---------------- 2 files changed, 19 insertions(+), 59 deletions(-) diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index ac2092b6..e49c82e7 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -58,7 +58,7 @@ class Origami::RoomsController < BaseOrigamiController @room.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new - @assigned_order_items = Array.new + # @assigned_order_items = Array.new booking.booking_orders.each do |booking_order| order = Order.find(booking_order.order_id) @customer = order.customer @@ -79,10 +79,10 @@ class Origami::RoomsController < BaseOrigamiController item.set_menu_items = arr_instance_item_sets end @order_items.push(item) - assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id) - if !assigned_order_items.nil? - @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id}) - end + # assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id) + # if !assigned_order_items.nil? + # @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id}) + # end end end end diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 70c0e723..efec7698 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -277,39 +277,19 @@ sub_total = sub_total + (order_item.price * order_item.qty) # unless order_item.price == 0 %> - <% if !@assigned_order_items.nil? %> - <% @assigned_order_items.each do |assigned_order_item| %> - <% if assigned_order_item.include? (order_item.order_items_id) %> - - <%= count %> - - <%= order_item.item_name %> - <% if !order_item.set_menu_items.nil? - order_item.set_menu_items.each do |item_instance| %> -
<%= item_instance %> - <% end - end %> - - <%= order_item.qty %> - <%= order_item.qty*order_item.price %> - - <% end %> - <% end %> - <% else %> - - <%= count %> - - <%= order_item.item_name %> - <% if !order_item.set_menu_items.nil? - order_item.set_menu_items.each do |item_instance| %> -
<%= item_instance %> - <% end - end %> - - <%= order_item.qty %> - <%= order_item.qty*order_item.price %> - - <% end %> + + <%= count %> + + <%= order_item.item_name %> + <% if !order_item.set_menu_items.nil? + order_item.set_menu_items.each do |item_instance| %> +
<%= item_instance %> + <% end + end %> + + <%= order_item.qty %> + <%= order_item.qty*order_item.price %> + <% # end @@ -365,26 +345,7 @@ @order_items.each do |order_item | count += 1 %> - <% if !@assigned_order_items.nil? %> - <% @assigned_order_items.each do |assigned_order_item| %> - <% if assigned_order_item.include? (order_item.order_items_id) %> - - <%= count %> - - <%= order_item.item_name %> - <% if !order_item.set_menu_items.nil? - order_item.set_menu_items.each do |item_instance| %> -
<%= item_instance %> - <% end - end %> - - <%= order_item.qty %> - <%= order_item.qty*order_item.price %> - - <% end %> - <% end %> - <% else %> - + <%= count %> <%= order_item.item_name %> @@ -397,7 +358,6 @@ <%= order_item.qty %> <%= order_item.qty*order_item.price %> - <% end %> <% end From 5523ff6fc17be50b8e57831cf70e49ddaab9873f Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 26 Feb 2018 11:24:47 +0630 Subject: [PATCH 60/98] check product sale report --- app/controllers/oqs/home_controller.rb | 26 +-- .../origami/payments_controller.rb | 2 +- .../reports/product_sale_controller.rb | 9 +- app/models/sale.rb | 2 +- app/views/oqs/home/index.html.erb | 12 +- app/views/origami/payments/show.html.erb | 2 +- app/views/reports/product_sale/index.html.erb | 202 +++++++++--------- 7 files changed, 125 insertions(+), 130 deletions(-) diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index d8642df4..78c2434b 100755 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -14,19 +14,19 @@ class Oqs::HomeController < BaseOqsController @queue_stations = OrderQueueStation.all @queue_completed_item = completed_order(@filter) - # if !@queue_completed_item.empty? - # @queue_completed_item.each do |queue_item| - # if !queue_item.set_menu_items.nil? - # instance_item_sets = JSON.parse(JSON.parse(queue_item.set_menu_items)) - # arr_instance_item_sets = Array.new - # instance_item_sets.each do |instance_item| - # item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name - # arr_instance_item_sets.push(item_instance_name) - # end - # queue_item.set_menu_items = arr_instance_item_sets - # end - # end - # end + if !@queue_completed_item.empty? + @queue_completed_item.each do |queue_item| + if !queue_item.set_menu_items.nil? + instance_item_sets = JSON.parse(JSON.parse(queue_item.set_menu_items)) + arr_instance_item_sets = Array.new + instance_item_sets.each do |instance_item| + item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name + arr_instance_item_sets.push(item_instance_name) + end + queue_item.set_menu_items = arr_instance_item_sets + end + end + end if !@filter.nil? @count = queue_items_count_query(false,@filter) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 317743dd..80f429a3 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -87,7 +87,7 @@ class Origami::PaymentsController < BaseOrigamiController #end rounding adjustment sale_payment = SalePayment.new - sale_payment.process_payment(saleObj, @usercurrent_user.name, cash, "cash") + sale_payment.process_payment(saleObj, current_user.name, cash, "cash") render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error "}) rebate_amount = nil diff --git a/app/controllers/reports/product_sale_controller.rb b/app/controllers/reports/product_sale_controller.rb index afb4b537..a2ba1c7f 100644 --- a/app/controllers/reports/product_sale_controller.rb +++ b/app/controllers/reports/product_sale_controller.rb @@ -2,18 +2,19 @@ class Reports::ProductSaleController < BaseReportController authorize_resource :class => false def index - order_by = 'desc' + @order_by = 'desc' if !params[:order_by].nil? - order_by = params[:order_by] + @order_by = params[:order_by] end - - @sale_data = Sale.get_menu_item_query(order_by) + + @sale_data = Sale.get_menu_item_query(@order_by) # get printer info @print_settings = PrintSetting.get_precision_delimiter() respond_to do |format| format.html + format.json format.xls end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 4167d549..ee24ed15 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -877,7 +877,7 @@ def self.get_menu_item_query(order_by) " LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" + " LEFT JOIN sales s ON s.sale_id = si.sale_id") .group("mc.id, menu_items.name, si.qty, (CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END)") - .order("si.qty #{order_by}, menu_items.menu_category_id desc") + .order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}") end #product sale report query diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 1f25e275..2bb5a94e 100755 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -83,13 +83,13 @@ <%= qid.qty %> ] - <% if !qid.set_menu_items.nil? - qid.set_menu_items.each do |item_instance|%> -
+ <% if !qid.set_menu_items.nil? %> + <% qid.set_menu_items.each do |item_instance|%> +
<%= item_instance %> - - <% end - end %> +
+ <% end %> + <% end %>


<%= qid.options == "[]"? "" : qid.options %>

diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index c6f8f941..64ca49bd 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -441,7 +441,7 @@ var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1); var total = $('#amount_due').text(); var amt = parseFloat(total) - parseFloat(othertotal); - $('#cash').text(parseFloat(amt).toFixed(1)); + $('#cash').text(parseFloat(amt).toFixed(2)); update_balance(); break; } diff --git a/app/views/reports/product_sale/index.html.erb b/app/views/reports/product_sale/index.html.erb index ab3136a3..7c0f3108 100644 --- a/app/views/reports/product_sale/index.html.erb +++ b/app/views/reports/product_sale/index.html.erb @@ -1,127 +1,121 @@ - -
-
- +
+ +
+
+ -
-
-
-
- - +
+
+
+
+ + +
-
-
- - - - - - - - - - - - - - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - <% unless @sale_data.blank? %> - <% acc_arr = Array.new %> - <% cate_arr = Array.new %> +
+ <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end %> +
 <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.total") %>
+ + + + + + + + + + + + + <% unless @sale_data.blank? %> + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> - <% grand_total = 0 %> - <% total_qty = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> - <% @sale_data.each do |sale| %> - <% if sale.status_type != "Discount" && sale.status_type != "foc" - total_qty += sale.total_item - grand_total += sale.grand_total - end %> - <% if sale.status_type == "foc" && sale.price > 0 - total_qty += sale.total_item - grand_total += sale.grand_total - end %> + <% @sale_data.each do |sale| %> + <% if sale.status_type != "Discount" && sale.status_type != "foc" + total_qty += sale.total_item + grand_total += sale.grand_total + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + grand_total += sale.grand_total + end %> - - - <% if !cate_arr.include?(sale.menu_category_id) %> - - <% cate_arr.push(sale.menu_category_id) %> - <% else %> - - <% end %> - - - - - - - - - <% end %> - - - - - - - - - <% end %> - -
 <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.total") %>
 <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %>
Total<%= total_qty %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %>
+ +   + <% if !cate_arr.include?(sale.menu_category_id) %> + <%= sale.menu_category_name %> + <% cate_arr.push(sale.menu_category_id) %> + <% else %> +   + <% end %> + <%= sale.item_code rescue '-' %> + <%= sale.product_name rescue '-' %> + <%= sale.total_item rescue '-' %> + <%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> + + + + <% end %> + + + Total + <%= total_qty %> + + <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> + + + <% end %> + + +
- \ No newline at end of file From b38e98a22a739a4dc2fc2eacc5e51c40ea649daa Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 26 Feb 2018 16:56:57 +0630 Subject: [PATCH 62/98] update edit with remark --- .../origami/discounts_controller.rb | 6 +- .../origami/other_charges_controller.rb | 2 +- .../origami/payments_controller.rb | 4 +- .../origami/sale_edit_controller.rb | 16 ++-- app/models/sale.rb | 63 +++++++-------- app/models/sale_item.rb | 6 +- app/models/sale_payment.rb | 2 +- app/views/origami/discounts/index.html.erb | 2 +- app/views/origami/sale_edit/edit.html.erb | 79 ++++++++++++++++--- config/secrets.yml | 4 +- 10 files changed, 123 insertions(+), 61 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 1166a705..56389302 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -41,7 +41,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.product_name = di["name"] sale_item.item_instance_code = origin_sale_item.item_instance_code sale_item.product_alt_name = "" - sale_item.remark = "Discount" + sale_item.status = "Discount" sale_item.qty = -1 sale_item.unit_price = di["price"].to_f * (-1) @@ -123,7 +123,7 @@ class Origami::DiscountsController < BaseOrigamiController discount_items = [] #destroy all discount sale item sale.sale_items.each do |si| - if si.remark == "Discount" && si.price < 0 + if si.status == "Discount" && si.price < 0 sale.total_amount = (sale.total_amount + si.price.abs) discount_items.push(si) end @@ -277,7 +277,7 @@ class Origami::DiscountsController < BaseOrigamiController # sale_item.sale_id = sale_id # sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id # sale_item.product_name = product_name - # sale_item.remark = remark + # sale_item.status = remark # sale_item.qty = 1 # sale_item.unit_price = (0-discount_amount.to_f) diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index 51a1f7db..07cd177e 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -32,7 +32,7 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.product_code = "Other Charges" sale_item.product_name = "*" + di["name"] sale_item.product_alt_name = "" - sale_item.remark = "Other Charges" + sale_item.status = "Other Charges" sale_item.qty = 1 sale_item.unit_price = di["price"] diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 317743dd..c5418d10 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -307,12 +307,14 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - + if saleObj.discount_type == "member_discount" saleObj.update_attributes(rounding_adjustment: 0) saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0) end + saleObj.update_attributes(rounding_adjustment: 0) + sale_payment = SalePayment.new sale_payment.process_payment(saleObj, current_user.name, cash, "foc" ,remark) diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index c00c35f0..e87deb35 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -10,8 +10,10 @@ class Origami::SaleEditController < BaseOrigamiController # create item void. make duplicate old record and update qty and price def item_void saleitemId = params[:sale_item_id] + remark = params[:remark] saleitemObj = SaleItem.find(saleitemId) - saleitemObj.remark = 'void' + saleitemObj.status = 'void' + saleitemObj.remark = remark saleitemObj.save @newsaleitem = SaleItem.new @newsaleitem = saleitemObj.dup @@ -21,6 +23,7 @@ class Origami::SaleEditController < BaseOrigamiController @newsaleitem.is_taxable = 1 @newsaleitem.taxable_price = saleitemObj.taxable_price * -1 @newsaleitem.product_name = saleitemObj.product_name + ' (VOID)' + @newsaleitem.remark = remark @newsaleitem.save # re-calc tax @@ -36,8 +39,10 @@ class Origami::SaleEditController < BaseOrigamiController def item_foc saleitemId = params[:sale_item_id] + remark = params[:remark] saleitemObj = SaleItem.find(saleitemId) - saleitemObj.remark = 'foc' + saleitemObj.status = 'foc' + saleitemObj.remark = remark saleitemObj.save @newsaleitem = SaleItem.new @newsaleitem = saleitemObj.dup @@ -47,6 +52,7 @@ class Origami::SaleEditController < BaseOrigamiController @newsaleitem.taxable_price = saleitemObj.taxable_price * -1 @newsaleitem.price = saleitemObj.price * -1 @newsaleitem.product_name = saleitemObj.product_name + ' (FOC)' + @newsaleitem.remark = remark @newsaleitem.save # re-calc tax @@ -65,7 +71,7 @@ class Origami::SaleEditController < BaseOrigamiController # update_qty = params[:update_qty] # update_price = params[:update_price] # saleitemObj = SaleItem.find(saleitemId) - # saleitemObj.remark = 'void' + # saleitemObj.status = 'void' # saleitemObj.save # @newsaleitem = SaleItem.new # @newsaleitem = saleitemObj.dup @@ -117,7 +123,7 @@ class Origami::SaleEditController < BaseOrigamiController both = SaleItem.where('product_code=?', saleitemObj.product_code) both.each do |item| if item.qty.to_i > 0 - item.remark = nil + item.status = nil item.save end end @@ -142,7 +148,7 @@ class Origami::SaleEditController < BaseOrigamiController if item.qty.to_i < 0 item.destroy else - item.remark = nil + item.status = nil end item.save ProductCommission.remove_product_commission(item) diff --git a/app/models/sale.rb b/app/models/sale.rb index f0166491..47733557 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -92,7 +92,7 @@ class Sale < ApplicationRecord self.cashier_id = open_cashier[0].id self.cashier_name = open_cashier[0].name shift_id = ShiftSale.current_open_shift(open_cashier[0].id) - self.shift_sale_id = shift_id.id + self.shift_sale_id = current_shift.id else self.cashier_id = current_shift.employee_id self.cashier_name = Employee.find(current_shift.employee_id).name @@ -227,7 +227,7 @@ class Sale < ApplicationRecord sale_item.product_name = item.item_name sale_item.product_alt_name = item.alt_name sale_item.account_id = item.account_id - sale_item.remark = item.remark + sale_item.status = item.remark sale_item.qty = item.qty sale_item.unit_price = item.price @@ -255,7 +255,7 @@ class Sale < ApplicationRecord sale_item.product_name = instance.item_instance_name sale_item.product_alt_name = menu_item.alt_name sale_item.account_id = menu_item.account_id - sale_item.remark = nil + sale_item.status = nil sale_item.qty = item["quantity"] sale_item.unit_price = item["price"] @@ -381,7 +381,7 @@ class Sale < ApplicationRecord rounding_adjustment = 0 sales_items.each do |item| - if item.remark != 'void' && item.remark != 'foc' + if item.status != 'void' && item.status != 'foc' #compute each item and added to total subtotal_price = subtotal_price + item.price @@ -417,35 +417,36 @@ class Sale < ApplicationRecord tax_profiles = TaxProfile.all.order("order_by asc") 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 - sale_tax = SaleTax.new(:sale => sale) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate + if sale.payment_status != 'foc' + tax_profiles.each do |tax| + 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 - # substract , to give after discount - total_tax = total_taxable - total_discount - #include or execulive - if tax.inclusive - rate = tax.rate - divided_value = (100 + rate)/rate - sale_tax.tax_payable_amount = total_tax / divided_value - 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 - if shop.calc_tax_order - total_taxable = total_taxable + sale_tax.tax_payable_amount - end + # substract , to give after discount + total_tax = total_taxable - total_discount + #include or execulive + if tax.inclusive + rate = tax.rate + divided_value = (100 + rate)/rate + sale_tax.tax_payable_amount = total_tax / divided_value + 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 + if shop.calc_tax_order + total_taxable = total_taxable + sale_tax.tax_payable_amount + end - sale_tax.inclusive = tax.inclusive - sale_tax.save + sale_tax.inclusive = tax.inclusive + sale_tax.save + end end end end - sale.total_tax = total_tax_amount end @@ -757,7 +758,7 @@ end def self.get_item_query() query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item,i.qty as qty," + - "i.remark as status_type,"+ + "i.status as status_type,"+ " i.unit_price,i.price as price,i.product_name as product_name, mc.name as" + " menu_category_name,mc.id as menu_category_id ") @@ -776,7 +777,7 @@ end def self.get_other_charges() 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.remark as status_type,"+ + "i.status as status_type,"+ " i.unit_price as unit_price,i.product_name as product_name") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id") query = query.where("i.item_instance_code IS NULL AND i.product_code = 'Other Charges'") @@ -1227,7 +1228,7 @@ end def self.total_foc_items(today) query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .where("sales.sale_status = 'completed' and a.status='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .sum("a.qty") end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 465af104..64e0ec73 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -28,7 +28,7 @@ class SaleItem < ApplicationRecord def self.update_existing_item(qty, item, sale_id, type, item_price, price) # Original Item to add remark - item.remark = type + item.status = type item.save sale_item = SaleItem.new @@ -37,7 +37,7 @@ class SaleItem < ApplicationRecord sale_item.product_name = item.product_name + " (#{type.upcase})" sale_item.product_alt_name = item.product_alt_name sale_item.account_id = item.account_id - sale_item.remark = type + sale_item.status = type if type == "foc" || type == "promotion" || type == "void" sale_item.qty = qty * (-1) else @@ -99,7 +99,7 @@ class SaleItem < ApplicationRecord discount_account = {:name => a.title, :price => 0} # Check for actual sale items - sale_items.where("remark = 'Discount'").find_each do |si| + sale_items.where("status = 'Discount'").find_each do |si| if si.account_id == a.id discount_account[:price] = (discount_account[:price].abs + si.price.abs) * (1) end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 5b0da284..aff43626 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -194,7 +194,7 @@ class SalePayment < ApplicationRecord payment_status = false # add to sale item with foc - sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }' and remark is null") + sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }' and status is null") sale_items.each do|item| SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 72f4fd3c..51b1e717 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -38,7 +38,7 @@ <% @sale_data.sale_items.each do |sale_item| %> <% sub_total += sale_item.qty*sale_item.unit_price - if sale_item.price != 0 && sale_item.remark != "void" && sale_item.remark != "foc" + if sale_item.price != 0 && sale_item.status != "void" && sale_item.status != "foc" %> > diff --git a/app/views/origami/sale_edit/edit.html.erb b/app/views/origami/sale_edit/edit.html.erb index 940b497a..6e79f9cb 100755 --- a/app/views/origami/sale_edit/edit.html.erb +++ b/app/views/origami/sale_edit/edit.html.erb @@ -57,7 +57,7 @@ <%= sale_item.product_name %> - <% if sale_item.remark != 'void' && sale_item.remark != 'edit' && sale_item.remark != 'foc' %> + <% if sale_item.status != 'void' && sale_item.status != 'edit' && sale_item.status != 'foc' %> @@ -69,11 +69,12 @@ --> - - + + + - <% elsif sale_item.qty.to_i < 0 || sale_item.remark == 'edit' %> + <% elsif sale_item.qty.to_i < 0 || sale_item.status == 'edit' %> @@ -148,18 +149,48 @@
--> - -
- - - - + +
+ + + + +
+ + + \ No newline at end of file diff --git a/app/views/reports/product_sale/index.html.erb b/app/views/reports/product_sale/index.html.erb new file mode 100755 index 00000000..eb797122 --- /dev/null +++ b/app/views/reports/product_sale/index.html.erb @@ -0,0 +1,113 @@ + +
+
+ + +
+
+
+
+ + +
+
+ +
+ <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end %> + + + + + + + + + + + + + + <% unless @sale_data.blank? %> + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + + <% grand_total = 0 %> + <% total_qty = 0 %> + + <% @sale_data.each do |sale| %> + <% if sale.status_type != "Discount" && sale.status_type != "foc" + total_qty += sale.total_item + grand_total += sale.grand_total + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + grand_total += sale.grand_total + end %> + + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + + + + + + + <% end %> + + + + + + + + + <% end %> + +
 <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.total") %>
 <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %>
Total<%= total_qty %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %>
+
+
+
+
+
+ + \ No newline at end of file diff --git a/app/views/reports/product_sale/index.xls.erb b/app/views/reports/product_sale/index.xls.erb new file mode 100755 index 00000000..7123588c --- /dev/null +++ b/app/views/reports/product_sale/index.xls.erb @@ -0,0 +1,64 @@ +
+
+
+
+
+ + + + + + + + + + + + + + <% unless @sale_data.blank? %> + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + <% grand_total = 0 %> + <% total_qty = 0 %> + + <% @sale_data.each do |sale| %> + <% if sale.status_type != "Discount" && sale.status_type != "foc" + total_qty += sale.total_item + grand_total += sale.grand_total + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + grand_total += sale.grand_total + end %> + + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + + + + + <% end %> + + + + + + + + <% end %> + +
 <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.total") %>
 <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.unit_price rescue '-' %><%= sale.grand_total rescue '-' %>
Total<%= total_qty %><%= grand_total rescue '-' %>
+
+
+
+
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7d21aeb5..a189da13 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -373,6 +373,7 @@ scope "(:locale)", locale: /en|mm/ do resources :commission, :only => [:index, :show] resources :stock_check, :only => [:index, :show] resources :payment_method + resources :product_sale, :only => [:index, :show] get "receipt_no/get_shift_by_date", to: "receipt_no#get_shift_by_date", as: "get_shift_by_date" end From 90b7a7f201475396f88e4799cf6b24028f124069 Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 27 Feb 2018 10:04:48 +0630 Subject: [PATCH 67/98] change stock check for dashboard query --- app/models/stock_journal.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index 35bebca2..c2a12f4a 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -36,12 +36,20 @@ class StockJournal < ApplicationRecord journal.save end - def self.inventory_balances(today) - query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") + def self.inventory_balances(today,from,to) + if !from.nil? && !to.nil? + query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") + .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") + .where("stock_journals.created_at between '#{from}' and '#{to}'") + .group("mii.item_instance_name") + .order("mii.item_instance_name ASC") + else + query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") .where("DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'") .group("mii.item_instance_name") .order("mii.item_instance_name ASC") + end end end From 700ff91127f12940764141717a6fa5705836c89d Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 27 Feb 2018 10:27:52 +0630 Subject: [PATCH 68/98] product sale --- app/controllers/reports/product_sale_controller.rb | 5 ++++- app/views/layouts/_left_sidebar.html.erb | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/reports/product_sale_controller.rb b/app/controllers/reports/product_sale_controller.rb index 748c8716..38a77115 100755 --- a/app/controllers/reports/product_sale_controller.rb +++ b/app/controllers/reports/product_sale_controller.rb @@ -2,7 +2,10 @@ class Reports::ProductSaleController < BaseReportController authorize_resource :class => false def index - @order_by = params[:order_by] + @order_by = 'desc' + if !params[:order_by].nil? + @order_by = params[:order_by] + end @sale_data = Sale.get_menu_item_query(@order_by) diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index 9bffd4d7..de42e719 100755 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -122,6 +122,9 @@
  • Sale Items
  • +
  • + Product Sale +
  • Receipt
  • From d8243afaab0a06c85f6206eacd53f20ea2d92927 Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 27 Feb 2018 11:09:28 +0630 Subject: [PATCH 69/98] check = split btn --- app/views/origami/split_bill/index.html.erb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb index 12148e28..fdd07dd8 100755 --- a/app/views/origami/split_bill/index.html.erb +++ b/app/views/origami/split_bill/index.html.erb @@ -198,7 +198,7 @@ # Receipt No. Total - <% if !@current_user.nil? && @current_user.role == 'cashier' %> + <% if !@current_user.nil? && @current_user.role != 'waiter' %> Action <% end %> @@ -238,7 +238,9 @@
    <% if !@current_user.nil? && @current_user.role != 'waiter' %> - + <% if !@sale_data.empty? %> + + <% end %> <% end %> <% if !@orders.empty? %> From fc3cd1e72d3c17533181a3aacfdf1207b13b4fc5 Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 27 Feb 2018 11:33:51 +0630 Subject: [PATCH 70/98] check order item --- .../origami/split_bill_controller.rb | 26 ++++++++++--------- app/views/origami/split_bill/index.html.erb | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index 59dd3a71..9f8afd0d 100644 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -147,15 +147,15 @@ class Origami::SplitBillController < BaseOrigamiController end end - # puts order_id - # puts order_ids.count - # puts order_id_count - # puts order_items.count - # puts order_item_count + puts order_id + puts order_ids.count + puts order_id_count + puts order_items.count + puts order_item_count if !order_id.nil? if order_id_count > 1 - # puts "order_id_count > 1" + puts "order_id_count > 1" updated_order_id = Array.new order_ids.each do |odr_id| @@ -165,8 +165,8 @@ class Origami::SplitBillController < BaseOrigamiController end end - # puts "updated_order_id" - # puts updated_order_id + puts "updated_order_id" + puts updated_order_id if !updated_order_id.empty? order_ids.each do |odr_id| @@ -195,7 +195,7 @@ class Origami::SplitBillController < BaseOrigamiController end end - # puts new_order_status + puts new_order_status if new_order_status BookingOrder.find_by_order_id(odr_id).delete @@ -223,7 +223,7 @@ class Origami::SplitBillController < BaseOrigamiController end end else - # puts "order_id_count < 1" + puts "order_id_count < 1" new_order_status = true order_items.each do |order_item| orderItem = OrderItem.find_by_order_id(order_id) @@ -236,7 +236,7 @@ class Origami::SplitBillController < BaseOrigamiController end end - # puts new_order_status + puts new_order_status if new_order_status BookingOrder.find_by_order_id(order_id).delete @@ -266,7 +266,9 @@ class Origami::SplitBillController < BaseOrigamiController end end else - if order_ids.count == 1 && order_id_count > 0 && order_item_count == 1 + # puts order_ids + if order_ids.count == 1 && order_id_count == 0 && order_item_count == 1 + BookingOrder.find_by_order_id(order_ids[0]).delete BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]}) order_items.each do |order_item| update_order_item(order_ids[0], order_item) diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb index fdd07dd8..1db44d41 100755 --- a/app/views/origami/split_bill/index.html.erb +++ b/app/views/origami/split_bill/index.html.erb @@ -214,7 +214,7 @@ <%= sale_data.receipt_no %> <%= sale_data.grand_total %> - <% if !@current_user.nil? && @current_user.role == 'cashier' %> + <% if !@current_user.nil? && @current_user.role != 'waiter' %> From 3e0943275fd3d82c5917816d2a6be82586e3e51a Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 27 Feb 2018 11:35:26 +0630 Subject: [PATCH 71/98] check bacck btn --- app/views/origami/payments/show.html.erb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 60ea300a..355e9f37 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -320,10 +320,6 @@
    - + + + + <%elsif !modify_order && type%> + + + + + Select + + + <%else%> + + <%end%> +
    +
    + <% if type %> +
    +
    + ORDER DETAILS +
    + + <% if modify_order %> + <% if @table.nil? %> +
    Table :
    + + + <% else%> +
    Table : <%=@table.name%>
    + + + <% end%> + + + + + <% else%> + + <% end%> +
    + <% else %> +
    + ORDER DETAILS | Table-<%=@table.name%> + + + + +
    + <% end%> + +
    +
    +
    + + + + + + + + + + + + +
    #ItemsQTYPrice
    +
    + +
    +
    + + + + + + + + + + + + + <% if type && !modify_order%> + + <% end %> + \ No newline at end of file diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 0c3e7bb5..1e96edc7 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -1,585 +1,3 @@ - <%= stylesheet_link_tag 'addorder', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'addorder', 'data-turbolinks-track': 'reload' %> - - -<% type = request.path_info.include?('quick_service')%> -<% modify_order = request.path_info.include?('modify_order')%> - - - - -
    -
    - -
  • - - - <%= @menus[0].name %> - - - -
  • - -
    - - - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    - - <% if type && modify_order%> - - - - - <%elsif !modify_order && type%> - - - - - Select - - - <%else%> - - <%end%> -
    -
    - <% if type %> -
    -
    - ORDER DETAILS -
    - - <% if modify_order %> - <% if @table.nil? %> -
    Table :
    - - - <% else%> -
    Table : <%=@table.name%>
    - - - <% end%> - - - - - <% else%> - - <% end%> -
    - <% else %> -
    - ORDER DETAILS | Table-<%=@table.name%> - - - - -
    - <% end%> - -
    -
    -
    - - - - - - - - - - - - -
    #ItemsQTYPrice
    -
    - -
    -
    - - - - - - - - - - - - - <% if type && !modify_order%> - - <% end %> - \ No newline at end of file +<%= render 'add_order' %> \ No newline at end of file diff --git a/app/views/origami/quick_service/_menu_item.json.jbuilder b/app/views/origami/quick_service/_menu_item.json.jbuilder new file mode 100755 index 00000000..a18645c8 --- /dev/null +++ b/app/views/origami/quick_service/_menu_item.json.jbuilder @@ -0,0 +1,119 @@ +# Format for attributes json +attr_format = [] +# Format for attributes json +if item.item_attributes.count > 0 + item.item_attributes.each do|attr_id| + menu_attr = MenuItemAttribute.find(attr_id) + if attr_format.count == 0 + attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] }) + next + end + + attr_format.each do |af| + if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]} + if menu_attr.attribute_type == af[:type] + af[:values].push(menu_attr.name) + end + else + new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] } + attr_format.push(new_attr) + break + end + end + end +end + +# Format for option json +opt_format = [] +# Format for attributes json +if item.item_options.count > 0 + item.item_options.each do|opt| + menu_opt = MenuItemOption.find(opt) + if opt_format.count == 0 + opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] }) + next + end + + opt_format.each do |of| + if menu_opt.option_type.in? opt_format.map {|k| k[:type]} + if menu_opt.option_type == of[:type] + of[:values].push(menu_opt.name) + end + else + new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] } + opt_format.push(new_opt) + break + end + end + end +end + +#Menu Item Information +json.id item.id +json.code item.item_code +json.name item.name +json.alt_name item.alt_name +json.image item.image_path.url +json.description item.description +json.information item.information +json.type item.type +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 + +# Item Sets of Menu Item +json.item_sets item.item_sets do |its| + json.id its.id + json.name its.name + json.alt_name its.alt_name + json.min_selectable_qty its.min_selectable_qty + json.max_selectable_qty its.max_selectable_qty + json.instances its.menu_item_instances do |i| + json.id i.id + end +end + +json.attributes attr_format +json.options opt_format +# json.min_selectable_item item.min_selectable_item +# json.max_selectable_item item.max_selectable_item + +#Item instance +# if item.menu_item_instances.count == 1 then +# item_instance = item.menu_item_instances[0] +# json.price = item_instance.price +# json.is_available = item_instance.is_available +# json.is_on_promotion = item_instance.is_on_promotion +# json.promotion_price = item_instance.promotion_price +# json.item_attributes = item_instance.item_attributes + +json.instances item.menu_item_instances do |is| + if is.is_available + # Convert id to name for attributes + instance_attr = [] + is.item_attributes.each do |ia| + mItemAttr = MenuItemAttribute.find(ia).name + instance_attr.push(mItemAttr) + end + + json.id is.id + json.code is.item_instance_code + json.name is.item_instance_name + json.price is.price + json.is_available is.is_available + json.is_default is.is_default + json.is_on_promotion is.is_on_promotion + json.promotion_price is.promotion_price + json.values instance_attr + # json.item_sets is.item_sets + end +end + +#Child Menu items +# if (item.children) then +# json.set_items item.children.each do |item| +# json.partial! 'api/restaurant/menu/menu_item', item: item +# end +# end \ No newline at end of file diff --git a/app/views/origami/quick_service/get_all_product.json.jbuilder b/app/views/origami/quick_service/get_all_product.json.jbuilder new file mode 100755 index 00000000..01921c59 --- /dev/null +++ b/app/views/origami/quick_service/get_all_product.json.jbuilder @@ -0,0 +1,4 @@ + +json.array! @product, :id, :item_code, :name, :alt_name,:image_path, + :description,:information,:taxable,:unit_price, :created_at, + :updated_at, :created_by \ No newline at end of file diff --git a/app/views/origami/quick_service/get_menu.json.jbuilder b/app/views/origami/quick_service/get_menu.json.jbuilder new file mode 100644 index 00000000..bbe18fff --- /dev/null +++ b/app/views/origami/quick_service/get_menu.json.jbuilder @@ -0,0 +1 @@ +json.array! @menu_category \ No newline at end of file diff --git a/app/views/origami/quick_service/get_menu_category.json.jbuilder b/app/views/origami/quick_service/get_menu_category.json.jbuilder new file mode 100755 index 00000000..91f659e8 --- /dev/null +++ b/app/views/origami/quick_service/get_menu_category.json.jbuilder @@ -0,0 +1,8 @@ +if @menu.menu_items + json.menu_items @menu.menu_items do |item| + if item.is_available + json.partial! 'origami/addorders/menu_item', item: item + end + + end +end diff --git a/app/views/origami/quick_service/get_menu_sub_category.json.jbuilder b/app/views/origami/quick_service/get_menu_sub_category.json.jbuilder new file mode 100644 index 00000000..d391e4c5 --- /dev/null +++ b/app/views/origami/quick_service/get_menu_sub_category.json.jbuilder @@ -0,0 +1,9 @@ +if @sub_menu + json.sub_category @sub_menu.each do |sub_cat| + json.id sub_cat.id + json.code sub_cat.code + json.name sub_cat.name + json.menu_id sub_cat.menu_id + json.menu_category_id sub_cat.menu_category_id + end +end diff --git a/app/views/origami/quick_service/index.html.erb b/app/views/origami/quick_service/index.html.erb index e69de29b..7108125b 100644 --- a/app/views/origami/quick_service/index.html.erb +++ b/app/views/origami/quick_service/index.html.erb @@ -0,0 +1,3 @@ +<%= stylesheet_link_tag 'addorder', media: 'all', 'data-turbolinks-track': 'reload' %> +<%= javascript_include_tag 'addorder', 'data-turbolinks-track': 'reload' %> +<%= render 'origami/addorders/add_order' %> \ No newline at end of file From b073ebbeebcad845be1efcd7c4b59e1ba56976e2 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 28 Feb 2018 10:20:50 +0630 Subject: [PATCH 81/98] change ReceiptBillPdf --- app/models/print_setting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/print_setting.rb b/app/models/print_setting.rb index b4f17a62..d28b852b 100755 --- a/app/models/print_setting.rb +++ b/app/models/print_setting.rb @@ -3,6 +3,6 @@ class PrintSetting < ApplicationRecord validates_presence_of :name, :unique_code, :printer_name, :page_width, :page_height, :print_copies def self.get_precision_delimiter - PrintSetting.find_by_unique_code("CloseCashierPdf") + PrintSetting.find_by_unique_code("ReceiptBillPdf") end end From 32340c52e656e61566f93220e171d00ae65f26d9 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 28 Feb 2018 13:55:24 +0630 Subject: [PATCH 82/98] check discount calculation --- app/views/origami/discounts/index.html.erb | 266 ++++++++++++--------- 1 file changed, 158 insertions(+), 108 deletions(-) diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index eab4d888..ccb2c0e8 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -31,6 +31,7 @@
    + @@ -117,6 +118,7 @@
    +

    @@ -254,12 +256,9 @@ var cashier_type = "<%= @cashier_type %>"; var original_value=0; original_value = $('#discount-amount').val(); var input_type = $(this).attr("data-type"); - var grand_total = $('#order-grand-total').text(); - console.log(grand_total); switch (input_type) { case 'num': var input_value = $(this).attr("data-value"); - console.log(input_value); if (original_value == "0.0"){ $('#discount-amount').val(input_value); } @@ -332,24 +331,40 @@ var cashier_type = "<%= @cashier_type %>"; $("#net").on('click', function(e){ e.preventDefault(); var sale_id = $('#sale-id').text(); - var discount_value = parseFloat($('#discount-amount').val()); + var discount_value = $('#discount-amount').val(); + var sub_total = parseFloat($('#order-sub-total').text()); var ajax_url = "/origami/" + sale_id + "/discount"; + + if(discount_value!=""){ + if(discount_value > 0){ + if(parseFloat(discount_value) > sub_total){ + $("#discount-amount").val(""); + $("#discount-amountErr").html("Discount is greater than sub total!"); + }else{ + $("#discount-amountErr").html(""); + // Selected Items + var sale_items = get_selected_sale_items(); - // Selected Items - var sale_items = get_selected_sale_items(); + // Selected Account + var account_types = get_selected_account_types(); - // Selected Account - var account_types = get_selected_account_types(); + if(sale_items.length == 0 && account_types.length == 0){ + calculate_overall_discount(0, discount_value); + } + else { + calculate_item_discount(0, discount_value, sale_items, account_types); + } - if(sale_items.length == 0 && account_types.length == 0){ - calculate_overall_discount(0, discount_value); + // Remove Selection + selection_remove(); + } + }else{ + $("#discount-amountErr").html("Discount must be greater than 0!"); + } + }else{ + $("#discount-amountErr").html("can't be blank"); } - else { - calculate_item_discount(0, discount_value, sale_items, account_types); - } - - // Remove Selection - selection_remove(); + }); // Calculate Percentage Discount for Payment @@ -360,8 +375,7 @@ var cashier_type = "<%= @cashier_type %>"; var ajax_url = "/origami/" + sale_id + "/discount"; // Selected Items - var sale_items = get_selected_sale_items(); - + var sale_items = get_selected_sale_items(); // Selected Account var account_types = get_selected_account_types(); @@ -435,7 +449,6 @@ var cashier_type = "<%= @cashier_type %>"; // Selected Items var sale_items = get_selected_sale_items(); - console.log(sale_items.length); if(sale_items.length == 0){ //swal("Information!", "You have no selected item!"); swal ( "Oops" , "You have no selected item!" , "error" ); @@ -669,113 +682,150 @@ function calculate_item_discount(type, amount, sale_items, account_types){ var dis_amount = 0; var sub_total = 0; var total_discount = 0; + var arrItemName = ""; + $("#discount_itemsErr").html(""); + $("#discount-amountErr").html(""); // For Net Pay - if(type == 0){ - dis_amount = (0 - amount); - if(sale_items.length > 0){ - for(var i=0;i < sale_items.length;i++){ - // if(account_types.length > 0){ - // for(var j=0; j < account_types.length; j++){ - // if(sale_items[i].account_id == account_types[j].id){ - // // Discount Items - // var discount_item_row = item_row_template(type, sale_items[i], dis_amount, amount); - // $("#order-items-table tbody").append(discount_item_row); - // total_discount = total_discount + amount; - // } - // } - // } - // else { - var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); - $("#order-items-table tbody").append(discount_item_row); - total_discount = total_discount + amount; - // } - } - } - - // No Needs For Auto Selected - // if(account_types.length > 0){ - // var item_rows=get_item_rows(); - // if(item_rows.length > 0){ - // for(var k=0; k < item_rows.length; k++){ - // for(var j=0; j < account_types.length; j++){ - // if(item_rows[k].account_id == account_types[j].id){ - // // Discount Items - // var discount_item_row = item_row_template(type, item_rows[k], dis_amount, amount); - // $("#order-items-table tbody").append(discount_item_row); - // total_discount = total_discount + amount; - // } - // } - // } - // } - // else { - // alert("No Items!"); - // } - // } - - sub_total = origin_sub_total - total_discount; - } - - // For Percentage Pay - if(type == 1){ - if(amount > 100 ){ - swal({ - title:"Oops!", - text:'Percentage Value over 100!', - type: "error", - confirmButtonText: 'OK', - confirmButtonColor:"red" - }); - } - else{ - // Check sale items exists + if(origin_sub_total > 0){ + if(type == 0){ + dis_amount = (0 - amount); if(sale_items.length > 0){ for(var i=0;i < sale_items.length;i++){ // if(account_types.length > 0){ // for(var j=0; j < account_types.length; j++){ // if(sale_items[i].account_id == account_types[j].id){ // // Discount Items - // dis_amount = 0 - ((sale_items[i].price * amount)/100); - // var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); + // var discount_item_row = item_row_template(type, sale_items[i], dis_amount, amount); // $("#order-items-table tbody").append(discount_item_row); - // total_discount = total_discount + dis_amount; + // total_discount = total_discount + amount; // } // } // } // else { - dis_amount = 0 - ((sale_items[i].price * amount)/100); - var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); - $("#order-items-table tbody").append(discount_item_row); - total_discount = total_discount + dis_amount; + if(parseFloat(amount) > parseFloat(sale_items[i].price)){ + arrItemName += ", " + sale_items[i].name; + }else{ + var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); + total_discount = parseFloat(total_discount) + parseFloat(amount); + + if(parseFloat(origin_sub_total) >= parseFloat(total_discount)){ + $("#order-items-table tbody").append(discount_item_row); + }else{ + total_discount = parseFloat(total_discount) - parseFloat(amount); + $("#discount-amountErr").html("Discount is greater than sub total!"); + } + } + // } } - sub_total = origin_sub_total + total_discount; } + + if(arrItemName!=""){ + arrItemName = arrItemName.substr(2); + if(arrItemName.match(/,/g || []) != null){ + if(arrItemName.match(/,/g || []).length >= 1){ + $("#discount_itemsErr").html("Discount is greater than "+arrItemName+" prices"); + } + }else{ + $("#discount_itemsErr").html("Discount is greater than "+arrItemName+" price"); + } + + } + + // No Needs For Auto Selected + // if(account_types.length > 0){ + // var item_rows=get_item_rows(); + // if(item_rows.length > 0){ + // for(var k=0; k < item_rows.length; k++){ + // for(var j=0; j < account_types.length; j++){ + // if(item_rows[k].account_id == account_types[j].id){ + // // Discount Items + // var discount_item_row = item_row_template(type, item_rows[k], dis_amount, amount); + // $("#order-items-table tbody").append(discount_item_row); + // total_discount = total_discount + amount; + // } + // } + // } + // } + // else { + // alert("No Items!"); + // } + // } + + sub_total = parseFloat(origin_sub_total) - parseFloat(total_discount); } - // No Needs For Auto Selected - // Check account types exists - // if(account_types.length > 0){ - // var item_rows=get_item_rows(); - // console.log(account_types); - // if(item_rows.length > 0){ - // for(var k=0; k < item_rows.length; k++){ - // for(var j=0; j < account_types.length; j++){ - // if(item_rows[k].account_id == account_types[j].id){ - // // Discount Items - // dis_amount = 0 - ((item_rows[k].price * amount)/100); - // var discount_item_row = item_row_template(type, item_rows[k], dis_amount, amount); - // $("#order-items-table tbody").append(discount_item_row); - // total_discount = total_discount + dis_amount; - // } - // } - // } - // } - // else { - // alert("No Items!"); - // } - // } + + // For Percentage Pay + if(type == 1){ + if(amount > 100 ){ + swal({ + title:"Oops!", + text:'Percentage Value over 100!', + type: "error", + confirmButtonText: 'OK', + confirmButtonColor:"red" + }); + } + else{ + // Check sale items exists + if(sale_items.length > 0){ + for(var i=0;i < sale_items.length;i++){ + // if(account_types.length > 0){ + // for(var j=0; j < account_types.length; j++){ + // if(sale_items[i].account_id == account_types[j].id){ + // // Discount Items + // dis_amount = 0 - ((sale_items[i].price * amount)/100); + // var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); + // $("#order-items-table tbody").append(discount_item_row); + // total_discount = total_discount + dis_amount; + // } + // } + // } + // else { + dis_amount = 0 - ((sale_items[i].price * amount)/100); + var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); + + total_discount = total_discount + dis_amount; + if(parseFloat(origin_sub_total) >= parseFloat(total_discount)){ + $("#order-items-table tbody").append(discount_item_row); + }else{ + total_discount = total_discount - dis_amount; + $("#discount-amountErr").html("Discount is greater than sub total!"); + } + // } + } + sub_total = parseFloat(origin_sub_total) + parseFloat(total_discount); + } + } + // No Needs For Auto Selected + // Check account types exists + // if(account_types.length > 0){ + // var item_rows=get_item_rows(); + // console.log(account_types); + // if(item_rows.length > 0){ + // for(var k=0; k < item_rows.length; k++){ + // for(var j=0; j < account_types.length; j++){ + // if(item_rows[k].account_id == account_types[j].id){ + // // Discount Items + // dis_amount = 0 - ((item_rows[k].price * amount)/100); + // var discount_item_row = item_row_template(type, item_rows[k], dis_amount, amount); + // $("#order-items-table tbody").append(discount_item_row); + // total_discount = total_discount + dis_amount; + // } + // } + // } + // } + // else { + // alert("No Items!"); + // } + // } + } + + $("#order-sub-total").text(parseFloat(sub_total).toFixed(2)); + }else{ + $("#discount-amountErr").html("Discount is greater than sub total!"); } - $("#order-sub-total").text(sub_total); } function item_row_template(type, item, discount_amount, amount){ From 1d70a9f1781ec41d69110e58343a461c0677e65f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 28 Feb 2018 14:20:22 +0630 Subject: [PATCH 83/98] update fixed issues for quickservice from sqa --- app/assets/javascripts/addorder.js | 69 +-- app/assets/stylesheets/addorder.scss | 2 +- .../origami/addorders_controller.rb | 2 +- .../origami/payments_controller.rb | 13 + .../origami/pending_order_controller.rb | 8 +- .../origami/quick_service_controller.rb | 3 +- .../origami/addorders/_add_order.html.erb | 584 ------------------ app/views/origami/addorders/detail.html.erb | 581 ++++++++++++++++- app/views/origami/addorders/index.html.erb | 111 ---- app/views/origami/payments/show.html.erb | 12 +- app/views/origami/pending_order/show.html.erb | 2 +- .../quick_service/_menu_item.json.jbuilder | 119 ---- .../get_all_product.json.jbuilder | 4 - .../quick_service/get_menu.json.jbuilder | 1 - .../get_menu_category.json.jbuilder | 8 - .../get_menu_sub_category.json.jbuilder | 9 - .../origami/quick_service/index.html.erb | 3 - 17 files changed, 641 insertions(+), 890 deletions(-) delete mode 100644 app/views/origami/addorders/_add_order.html.erb delete mode 100755 app/views/origami/addorders/index.html.erb delete mode 100755 app/views/origami/quick_service/_menu_item.json.jbuilder delete mode 100755 app/views/origami/quick_service/get_all_product.json.jbuilder delete mode 100644 app/views/origami/quick_service/get_menu.json.jbuilder delete mode 100755 app/views/origami/quick_service/get_menu_category.json.jbuilder delete mode 100644 app/views/origami/quick_service/get_menu_sub_category.json.jbuilder diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 475652af..de1024ea 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -1,7 +1,7 @@ $(function() { var role = $('#role').val(); - type = $('#type').val(); - modify_order = $('#modify_order').val(); + type = window.location.href.indexOf("quick_service"); + modify_order = window.location.href.indexOf("modify_order"); //click menu sidebar menu category $(".product").on("click", function(){ var url = $(this).attr('data-ref'); @@ -88,13 +88,16 @@ $(function() { function show_menu_item_list(url_item){ var menu_list = $('.menu_items_list'); menu_list.empty(); - - if (modify_order=="true" && type =="true") { - url_item = '../../../addorders/'+url_item; - }if(modify_order=="false" && type =="true"){ - url_item = 'addorders/'+url_item - }else{ - url_item = url_item; + + type = window.location.href.indexOf("quick_service"); + modify_order = window.location.href.indexOf("modify_order"); + if (type != -1 && modify_order != -1) { + url_item = '../../../addorders/'+url_item; + }if(modify_order == -1 && type != -1){ + url_item = 'addorders/'+url_item; + } + if (type ==-1 && modify_order == -1){ + url_item = url_item } //Start Ajax @@ -104,8 +107,6 @@ $(function() { data: {}, dataType: "json", success: function(data) { - console.log(data); - console.log("ememem") var menu_items_list = $('.menu_items_list'); menu_items_list.empty(); menu_items = data.menu_items; @@ -758,14 +759,10 @@ $(function() { e.preventDefault(); $("#oqs_loading_wrapper").show(); - type = $('#type').val(); - if (type == 'true') { - // if (role == 'waiter') { - type = 'quick_service' - // }else{ - // type = 'cashier' - // } + type = window.location.href.indexOf("quick_service"); + if (type != 'true') { + type = 'quick_service' var table_type = $('#table_type').text(); var table_id = $('#table_id').val(); var customer_id = $('#customer_id').val(); @@ -785,15 +782,15 @@ $(function() { var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "",'booking_id':booking_id, 'table_id': table_id, - 'order_items': order_items }; + 'order_items': order_items,'create_type' : "create_only" }; }else{ var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "", 'table_id': table_id, - 'order_items': order_items }; + 'order_items': order_items,'create_type' : "create_only" }; } - - if (table_id.length>0 || role == 'waiter') { + + // if (table_id.length>0 || role == 'waiter') { $.ajax({ type: "POST", url: ajax_url, @@ -812,12 +809,12 @@ $(function() { } } }); - }else{ - $(this).removeAttr('disabled', ''); - $("#oqs_loading_wrapper").hide(); + // }else{ + // $(this).removeAttr('disabled', ''); + // $("#oqs_loading_wrapper").hide(); - swal("Opps","Please Select Table or Room","warning"); - } + // swal("Opps","Please Select Table or Room","warning"); + // } }); @@ -826,9 +823,10 @@ $(function() { $(this).attr('disabled', 'disabled'); e.preventDefault(); type = "quick_service" + modify_order = window.location.href.indexOf("modify_order"); $("#oqs_loading_wrapper").show(); console.log(modify_order) - if (modify_order == "true") { + if (modify_order !=-1) { console.log($('#sale_id').text()) var ajax_url = '../../../quick_service/update_modify_order'; var table_type = $('#table_type').text(); @@ -850,12 +848,12 @@ $(function() { var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "",'booking_id':booking_id, 'table_id': table_id, - 'order_items': order_items,'sale_id': sale_id }; + 'order_items': order_items,'sale_id': sale_id,'create_type': "create_pay" }; }else{ var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "", 'table_id': table_id, - 'order_items': order_items,'sale_id': sale_id }; + 'order_items': order_items,'sale_id': sale_id,'create_type': "create_pay" }; } $.ajax({ @@ -987,7 +985,7 @@ $(function() { $("#back").on("click", function(){ var table_id = $('#table_id').text(); var table_type = $('#table_type').text(); - type = $('#type').val(); + type = window.location.href.indexOf("quick_service"); if (type == 'true') { var table_type = $('#table_id').find("option:selected").data('type'); var table_id = $('#table_id').val(); @@ -1113,11 +1111,12 @@ $(function() { //show menu item list when click menu category function show_sub_category_list(url,sub_category){ - if (modify_order == "true" && type =="true") { + if (type != -1 && modify_order != -1) { var url = "../../../addorders/"+url; - }if(modify_order=="false" && type =="true"){ + }if(modify_order== -1 && type != -1){ var url = 'addorders/'+url; - }else{ + } + if (type ==-1 && modify_order == -1){ var url = url; } @@ -1130,8 +1129,6 @@ $(function() { data: {}, dataType: "json", success: function(data) { - console.log(data) - console.log("ffffffffff") var sub_category_list = $('.sub_category_list'); sub_category_list.empty(); data = data.sub_category; diff --git a/app/assets/stylesheets/addorder.scss b/app/assets/stylesheets/addorder.scss index faff5850..d8adba16 100755 --- a/app/assets/stylesheets/addorder.scss +++ b/app/assets/stylesheets/addorder.scss @@ -175,7 +175,7 @@ section.content{ text-align: center; } -.add_icon{ +.menu_item_box{ cursor: pointer; } diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 9c19bbf2..c9b1bc44 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -156,7 +156,7 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController end @status, @booking = @order.generate - if current_user.role != "waiter" + if current_user.role != "waiter" && params[:create_type] == "create_pay" if @status && @booking && @order.source == 'quick_service' @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index fa7e5914..970095e9 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -403,6 +403,19 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil) + + if params[:type] == "quick_service" + booking = Booking.find_by_sale_id(sale_id) + if booking.dining_facility_id.to_i>0 + table_id = booking.dining_facility_id + else + table_id = 0 + end + + booking.booking_orders.each do |order| + Order.pay_process_order_queue(order.order_id,table_id) + end + end end end end diff --git a/app/controllers/origami/pending_order_controller.rb b/app/controllers/origami/pending_order_controller.rb index 4ed81121..d738a0a5 100644 --- a/app/controllers/origami/pending_order_controller.rb +++ b/app/controllers/origami/pending_order_controller.rb @@ -23,15 +23,15 @@ class Origami::PendingOrderController < BaseOrigamiController @order_items = Array.new @bookings.booking_orders.each do |booking_order| - order = Order.find(booking_order.order_id) - if (order.status == "new") - order.order_items.each do |item| + @order = Order.find(booking_order.order_id) + if (@order.status == "new") + @order.order_items.each do |item| @order_items.push(item) end end end end - + puts @status if @bookings.dining_facility_id.to_i > 0 @table_id = Booking.find(@bookings.booking_id).dining_facility_id @dining = DiningFacility.find(@table_id) diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index 8516c493..44dcfcb8 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -14,7 +14,7 @@ class Origami::QuickServiceController < ApplicationController # @rooms = Room.all.active.order('zone_id asc').group("zone_id") # @all_table = Table.all.active.order('status desc') # @all_room = Room.all.active.order('status desc') - # render "origami/addorders/detail" + render "origami/addorders/detail" end def modify_order @@ -51,6 +51,7 @@ class Origami::QuickServiceController < ApplicationController else @booking = nil end + render "origami/addorders/detail" end def update_modify_order diff --git a/app/views/origami/addorders/_add_order.html.erb b/app/views/origami/addorders/_add_order.html.erb deleted file mode 100644 index efe21d2a..00000000 --- a/app/views/origami/addorders/_add_order.html.erb +++ /dev/null @@ -1,584 +0,0 @@ - - - - -<% type = request.path_info.include?('quick_service')%> -<% modify_order = request.path_info.include?('modify_order')%> - - - - -
    -
    - -
  • - - - <%= @menus[0].name %> - - - -
  • - -
    - - - -
    -
    -
    -
    - -
    -
    -
    -
    - -
    - - <% if type && modify_order%> - - - - - <%elsif !modify_order && type%> - - - - - Select - - - <%else%> - - <%end%> -
    -
    - <% if type %> -
    -
    - ORDER DETAILS -
    - - <% if modify_order %> - <% if @table.nil? %> -
    Table :
    - - - <% else%> -
    Table : <%=@table.name%>
    - - - <% end%> - - - - - <% else%> - - <% end%> -
    - <% else %> -
    - ORDER DETAILS | Table-<%=@table.name%> - - - - -
    - <% end%> - -
    -
    -
    -
    - - - - - - - - - - - -
    #ItemsQTYPrice
    -
    - -
    -
    - - - - - - - - - - - - - <% if type && !modify_order%> - - <% end %> - \ No newline at end of file diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 1e96edc7..9190ccf7 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -1,3 +1,582 @@ <%= stylesheet_link_tag 'addorder', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'addorder', 'data-turbolinks-track': 'reload' %> -<%= render 'add_order' %> \ No newline at end of file + + +<% type = request.path_info.include?('quick_service')%> +<% modify_order = request.path_info.include?('modify_order')%> + + +
    +
    + +
  • + + + <%= @menus[0].name %> + + + +
  • + +
    + + + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    + + <% if type && modify_order%> + + + + + <%elsif !modify_order && type%> + + + + + Select + + + <%else%> + + <%end%> +
    +
    + <% if type %> +
    +
    + ORDER DETAILS +
    + + <% if modify_order %> + <% if @table.nil? %> +
    Table :
    + + + <% else%> +
    Table : <%=@table.name%>
    + + + <% end%> + + + + + <% else%> + + <% end%> +
    + <% else %> +
    + ORDER DETAILS | Table-<%=@table.name%> + + + + +
    + <% end%> + +
    +
    +
    + + + + + + + + + + + + +
    #ItemsQTYPrice
    +
    + +
    +
    + + + + + + + + + + + + + <% if type && !modify_order%> + + <% end %> + \ No newline at end of file diff --git a/app/views/origami/addorders/index.html.erb b/app/views/origami/addorders/index.html.erb deleted file mode 100755 index c45339c2..00000000 --- a/app/views/origami/addorders/index.html.erb +++ /dev/null @@ -1,111 +0,0 @@ -
    -
    - -
    - -
    - <% @tables.each do |zone| %> -

    Zone : <%=zone.zone.name%>

    -
    - - <% @all_table.each do |table| %> - <% if zone.zone_id == table.zone_id %> -
    " data-id = "<%= table.id %>"> -
    - -

    <%= table.name %>

    -

    Seat : <%= table.seater %>

    -
    -
    - <% end %> <% end %> -
    - <% end %> -
    - -
    - <% @rooms.each do |zone| %> -

    Zone : <%=zone.zone.name%>

    -
    - - <% @all_room.each do |room| %> - <% if zone.zone_id == room.zone_id %> -
    " data-id = "<%= room.id %>"> -
    - -

    <%= room.name %>

    -

    Seat : <%= room.seater %>

    -
    -
    - <% end %> <% end %> -
    - <% end %> -
    - -
    -
    - -
    - -
    -
    - - diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 60ea300a..cb213a38 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -324,10 +324,6 @@ reply Back - <%end%> - <% if current_user.role != "waiter"%> + <% if current_user.role != "waiter" && @status != "order"%> <%end%> <% if @status != "sale"%> diff --git a/app/views/origami/quick_service/_menu_item.json.jbuilder b/app/views/origami/quick_service/_menu_item.json.jbuilder deleted file mode 100755 index a18645c8..00000000 --- a/app/views/origami/quick_service/_menu_item.json.jbuilder +++ /dev/null @@ -1,119 +0,0 @@ -# Format for attributes json -attr_format = [] -# Format for attributes json -if item.item_attributes.count > 0 - item.item_attributes.each do|attr_id| - menu_attr = MenuItemAttribute.find(attr_id) - if attr_format.count == 0 - attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] }) - next - end - - attr_format.each do |af| - if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]} - if menu_attr.attribute_type == af[:type] - af[:values].push(menu_attr.name) - end - else - new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] } - attr_format.push(new_attr) - break - end - end - end -end - -# Format for option json -opt_format = [] -# Format for attributes json -if item.item_options.count > 0 - item.item_options.each do|opt| - menu_opt = MenuItemOption.find(opt) - if opt_format.count == 0 - opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] }) - next - end - - opt_format.each do |of| - if menu_opt.option_type.in? opt_format.map {|k| k[:type]} - if menu_opt.option_type == of[:type] - of[:values].push(menu_opt.name) - end - else - new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] } - opt_format.push(new_opt) - break - end - end - end -end - -#Menu Item Information -json.id item.id -json.code item.item_code -json.name item.name -json.alt_name item.alt_name -json.image item.image_path.url -json.description item.description -json.information item.information -json.type item.type -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 - -# Item Sets of Menu Item -json.item_sets item.item_sets do |its| - json.id its.id - json.name its.name - json.alt_name its.alt_name - json.min_selectable_qty its.min_selectable_qty - json.max_selectable_qty its.max_selectable_qty - json.instances its.menu_item_instances do |i| - json.id i.id - end -end - -json.attributes attr_format -json.options opt_format -# json.min_selectable_item item.min_selectable_item -# json.max_selectable_item item.max_selectable_item - -#Item instance -# if item.menu_item_instances.count == 1 then -# item_instance = item.menu_item_instances[0] -# json.price = item_instance.price -# json.is_available = item_instance.is_available -# json.is_on_promotion = item_instance.is_on_promotion -# json.promotion_price = item_instance.promotion_price -# json.item_attributes = item_instance.item_attributes - -json.instances item.menu_item_instances do |is| - if is.is_available - # Convert id to name for attributes - instance_attr = [] - is.item_attributes.each do |ia| - mItemAttr = MenuItemAttribute.find(ia).name - instance_attr.push(mItemAttr) - end - - json.id is.id - json.code is.item_instance_code - json.name is.item_instance_name - json.price is.price - json.is_available is.is_available - json.is_default is.is_default - json.is_on_promotion is.is_on_promotion - json.promotion_price is.promotion_price - json.values instance_attr - # json.item_sets is.item_sets - end -end - -#Child Menu items -# if (item.children) then -# json.set_items item.children.each do |item| -# json.partial! 'api/restaurant/menu/menu_item', item: item -# end -# end \ No newline at end of file diff --git a/app/views/origami/quick_service/get_all_product.json.jbuilder b/app/views/origami/quick_service/get_all_product.json.jbuilder deleted file mode 100755 index 01921c59..00000000 --- a/app/views/origami/quick_service/get_all_product.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ - -json.array! @product, :id, :item_code, :name, :alt_name,:image_path, - :description,:information,:taxable,:unit_price, :created_at, - :updated_at, :created_by \ No newline at end of file diff --git a/app/views/origami/quick_service/get_menu.json.jbuilder b/app/views/origami/quick_service/get_menu.json.jbuilder deleted file mode 100644 index bbe18fff..00000000 --- a/app/views/origami/quick_service/get_menu.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.array! @menu_category \ No newline at end of file diff --git a/app/views/origami/quick_service/get_menu_category.json.jbuilder b/app/views/origami/quick_service/get_menu_category.json.jbuilder deleted file mode 100755 index 91f659e8..00000000 --- a/app/views/origami/quick_service/get_menu_category.json.jbuilder +++ /dev/null @@ -1,8 +0,0 @@ -if @menu.menu_items - json.menu_items @menu.menu_items do |item| - if item.is_available - json.partial! 'origami/addorders/menu_item', item: item - end - - end -end diff --git a/app/views/origami/quick_service/get_menu_sub_category.json.jbuilder b/app/views/origami/quick_service/get_menu_sub_category.json.jbuilder deleted file mode 100644 index d391e4c5..00000000 --- a/app/views/origami/quick_service/get_menu_sub_category.json.jbuilder +++ /dev/null @@ -1,9 +0,0 @@ -if @sub_menu - json.sub_category @sub_menu.each do |sub_cat| - json.id sub_cat.id - json.code sub_cat.code - json.name sub_cat.name - json.menu_id sub_cat.menu_id - json.menu_category_id sub_cat.menu_category_id - end -end diff --git a/app/views/origami/quick_service/index.html.erb b/app/views/origami/quick_service/index.html.erb index 7108125b..e69de29b 100644 --- a/app/views/origami/quick_service/index.html.erb +++ b/app/views/origami/quick_service/index.html.erb @@ -1,3 +0,0 @@ -<%= stylesheet_link_tag 'addorder', media: 'all', 'data-turbolinks-track': 'reload' %> -<%= javascript_include_tag 'addorder', 'data-turbolinks-track': 'reload' %> -<%= render 'origami/addorders/add_order' %> \ No newline at end of file From 8e4c3864daf111cf42ca09834f8325c75fdfa870 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 28 Feb 2018 15:27:29 +0630 Subject: [PATCH 84/98] check query for product sales --- app/models/sale.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 7aa18282..2138405c 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -852,7 +852,7 @@ def self.get_menu_item_query(order_by) acc.title as account_name, mii.item_instance_code as item_code, " + "(CASE WHEN si.qty > 0 THEN SUM(si.qty) ELSE 0 END) as total_item," + - "(CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END) as unit_price," + + "(CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END) as unit_price," + "(CASE WHEN (si.qty * si.unit_price) > 0 THEN (si.qty * si.unit_price) ELSE 0 END) as grand_total," + "mii.price as unit_price, menu_items.name as product_name, mc.name as" + @@ -862,8 +862,8 @@ def self.get_menu_item_query(order_by) " LEFT JOIN accounts acc ON acc.id = menu_items.account_id" + " LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" + " LEFT JOIN sales s ON s.sale_id = si.sale_id") - .group("mc.id, menu_items.name, si.qty, (CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END)") - .order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}") + .group("mc.id, menu_items.name, si.qty, (CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END)") + .order("menu_items.menu_category_id #{order_by}, si.qty #{order_by}") end #product sale report query @@ -1080,7 +1080,7 @@ end " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") .where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+ - "and payment_status='paid' and sale_status= 'completed'") + "and sale_status= 'completed' or i.remark!='void'") .group('mi.name') .order("SUM(i.qty) DESC").limit(20) else @@ -1088,7 +1088,7 @@ end " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ - "and payment_status='paid' and sale_status= 'completed'") + "and sale_status= 'completed' or i.remark!='void'") .group('mi.name') .order("SUM(i.qty) DESC").limit(20) end @@ -1100,7 +1100,7 @@ end " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") .where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+ - "and payment_status='paid' and sale_status= 'completed'") + "and sale_status= 'completed'") .group('mi.name') .order("SUM(i.qty) ASC").limit(20) else @@ -1108,7 +1108,7 @@ end " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ - "and payment_status='paid' and sale_status= 'completed'") + "and sale_status= 'completed'") .group('mi.name') .order("SUM(i.qty) ASC").limit(20) end From 7c8b5def810f66c1561383faa5355ba254d2da21 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 28 Feb 2018 15:42:07 +0630 Subject: [PATCH 85/98] check product sale --- app/models/sale.rb | 4 ++-- app/views/reports/product_sale/index.html.erb | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 2138405c..e433a999 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -862,8 +862,8 @@ def self.get_menu_item_query(order_by) " LEFT JOIN accounts acc ON acc.id = menu_items.account_id" + " LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" + " LEFT JOIN sales s ON s.sale_id = si.sale_id") - .group("mc.id, menu_items.name, si.qty, (CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END)") - .order("menu_items.menu_category_id #{order_by}, si.qty #{order_by}") + .group("si.qty, mc.id, menu_items.name, (CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END)") + .order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}") end #product sale report query diff --git a/app/views/reports/product_sale/index.html.erb b/app/views/reports/product_sale/index.html.erb index eb797122..b8ab6598 100755 --- a/app/views/reports/product_sale/index.html.erb +++ b/app/views/reports/product_sale/index.html.erb @@ -69,12 +69,7 @@   - <% if !cate_arr.include?(sale.menu_category_id) %> <%= sale.menu_category_name %> - <% cate_arr.push(sale.menu_category_id) %> - <% else %> -   - <% end %> <%= sale.item_code rescue '-' %> <%= sale.product_name rescue '-' %> <%= sale.total_item rescue '-' %> From 32818abf4917fb63c36c6317786a359c2310ac2c Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 28 Feb 2018 15:44:15 +0630 Subject: [PATCH 86/98] change in xls --- app/views/reports/product_sale/index.xls.erb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/views/reports/product_sale/index.xls.erb b/app/views/reports/product_sale/index.xls.erb index 7123588c..f0410810 100755 --- a/app/views/reports/product_sale/index.xls.erb +++ b/app/views/reports/product_sale/index.xls.erb @@ -34,12 +34,7 @@   - <% if !cate_arr.include?(sale.menu_category_id) %> <%= sale.menu_category_name %> - <% cate_arr.push(sale.menu_category_id) %> - <% else %> -   - <% end %> <%= sale.item_code rescue '-' %> <%= sale.product_name rescue '-' %> <%= sale.total_item rescue '-' %> From bb6b3794b3ca213c97654fcbf285f56ebd7d73fa Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Wed, 28 Feb 2018 16:16:14 +0630 Subject: [PATCH 87/98] Edit in dashboard Total Sale->Net Sale, Grand Total->Gross Sale to same with close_cashier_customise_pdf.rb --- 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 91cce7e3..a30cae23 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -164,7 +164,7 @@ <%= @summ_sale.total_receipt %> - <%= t("views.right_panel.detail.total") %> <%= t :sale %> : + <%= t("views.right_panel.detail.net") %> <%= t :sale %> : <%= number_with_precision( @summ_sale.total_amount, precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> @@ -176,7 +176,7 @@ <%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> - <%= t("views.right_panel.detail.grand_total") %> : + <%= t("views.right_panel.detail.gross_sale") %> : <%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> From 2f7d9523ec9c9571937703b51732562072d15955 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 28 Feb 2018 16:26:40 +0630 Subject: [PATCH 88/98] check product sale --- app/models/sale.rb | 9 +++-- app/views/reports/product_sale/index.html.erb | 38 ++++++++++--------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index e433a999..4a12715f 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -851,18 +851,19 @@ def self.get_menu_item_query(order_by) query = MenuItem.unscoped.select("acc.id as account_id, acc.title as account_name, mii.item_instance_code as item_code, " + - "(CASE WHEN si.qty > 0 THEN SUM(si.qty) ELSE 0 END) as total_item," + + "(CASE WHEN si.qty != '' THEN SUM(si.qty) ELSE 0 END) as total_item," + "(CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END) as unit_price," + "(CASE WHEN (si.qty * si.unit_price) > 0 THEN (si.qty * si.unit_price) ELSE 0 END) as grand_total," + - "mii.price as unit_price, menu_items.name as product_name, + "mii.price as unit_price, mii.item_instance_name as product_name, mc.name as" + - " menu_category_name,mc.id as menu_category_id, si.remark as status_type, si.price as price ") + " menu_category_name,mc.id as menu_category_id, si.remark as status_type, + si.price as price ") .joins(" LEFT JOIN menu_item_instances mii ON menu_items.id = mii.menu_item_id" + " LEFT JOIN menu_categories mc ON mc.id = menu_items.menu_category_id" + " LEFT JOIN accounts acc ON acc.id = menu_items.account_id" + " LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" + " LEFT JOIN sales s ON s.sale_id = si.sale_id") - .group("si.qty, mc.id, menu_items.name, (CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END)") + .group("mc.id, mii.item_instance_name, (CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END)") .order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}") end #product sale report query diff --git a/app/views/reports/product_sale/index.html.erb b/app/views/reports/product_sale/index.html.erb index b8ab6598..a62e0d73 100755 --- a/app/views/reports/product_sale/index.html.erb +++ b/app/views/reports/product_sale/index.html.erb @@ -47,6 +47,7 @@ <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.unit_price") %> <%= t("views.right_panel.detail.total") %> + <%= t("views.right_panel.detail.remark") %> @@ -58,24 +59,25 @@ <% total_qty = 0 %> <% @sale_data.each do |sale| %> - <% if sale.status_type != "Discount" && sale.status_type != "foc" - total_qty += sale.total_item - grand_total += sale.grand_total - end %> - <% if sale.status_type == "foc" && sale.price > 0 - total_qty += sale.total_item - grand_total += sale.grand_total - end %> + <% if sale.status_type != "Discount" && sale.status_type != "foc" + total_qty += sale.total_item + grand_total += sale.grand_total + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + grand_total += sale.grand_total + end %> - -   - <%= sale.menu_category_name %> - <%= sale.item_code rescue '-' %> - <%= sale.product_name rescue '-' %> - <%= sale.total_item rescue '-' %> - <%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> - + +   + <%= sale.menu_category_name %> + <%= sale.item_code rescue '-' %> + <%= sale.product_name rescue '-' %> + <%= sale.total_item rescue '-' %> + <%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> + <%= sale.status_type rescue '' %> + <% end %> @@ -84,7 +86,7 @@ Total <%= total_qty %> - <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> + <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> <% end %> From d9afdc7df5955412efcbd884d3cacb71dca02abf Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 28 Feb 2018 16:44:32 +0630 Subject: [PATCH 89/98] update product for account id 3 --- app/models/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/product.rb b/app/models/product.rb index 3c915a38..2d8cc013 100755 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -9,7 +9,7 @@ class Product < ApplicationRecord mt_instance = Product.find_by_item_code(item_code) if (!mt_instance.nil?) menu_item_hash[:type] = 'Product' - menu_item_hash[:account_id] = 1 + menu_item_hash[:account_id] = 3 menu_item_hash[:item_code] = mt_instance.item_code menu_item_hash[:item_instance_code] = mt_instance.item_code menu_item_hash[:name] = mt_instance.name.to_s From 4bb597cb9dbced4beffbe0e9fd079c6bc624b3b7 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 5 Mar 2018 10:28:36 +0630 Subject: [PATCH 90/98] update saleitem migrate for status --- db/migrate/20170403161857_create_sale_items.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/db/migrate/20170403161857_create_sale_items.rb b/db/migrate/20170403161857_create_sale_items.rb index 27cf7ac4..2135e715 100755 --- a/db/migrate/20170403161857_create_sale_items.rb +++ b/db/migrate/20170403161857_create_sale_items.rb @@ -8,6 +8,7 @@ class CreateSaleItems < ActiveRecord::Migration[5.1] t.string :product_name, :null => false t.string :product_alt_name, :null => false t.integer :account_id, :limit => 8, :null => false, :default => 1 + t.string :status t.string :remark t.decimal :qty, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :unit_price, :precision => 10, :scale => 2, :null => false, :default => 0.00 From 2c1f599990e00d1694da0c9f94f56ba1ea03a066 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 5 Mar 2018 13:53:25 +0630 Subject: [PATCH 91/98] update license --- app/controllers/install_controller.rb | 2 ++ config/initializers/action_controller.rb | 11 +++++------ config/secrets.yml | 4 ++-- config/shops.json | 13 +------------ 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index 353509c3..5aa7af06 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,4 +1,5 @@ class InstallController < BaseController + skip_before_action :lookup_domain skip_before_action :verify_authenticity_token # before_action :check_license @@ -34,6 +35,7 @@ class InstallController < BaseController if response[:status] redirect_to root_url, notice: response["message"] else + byebug redirect_to activate_path, notice: response["message"] end end diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 7cabe7f7..8f310dab 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -1,5 +1,4 @@ class ActionController::Base - before_action :lookup_domain, :set_locale private @@ -21,11 +20,11 @@ class ActionController::Base end else # check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end + if check_license + current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path + end end end diff --git a/config/secrets.yml b/config/secrets.yml index b74dcdbc..7930204e 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -12,7 +12,7 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 - sx_provision_url: 192.168.1.125:3002/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api + sx_provision_url: connect.smartsales.dev/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L @@ -24,7 +24,7 @@ test: # instead read values from the environment. production: secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22 - sx_provision_url: connect.smartsales.asia/api #192.168.1.147:3002/api + sx_provision_url: connect.smartsales.dev/api #192.168.1.147:3002/api server_mode: cloud cipher_type: AES-256-CBC sx_key: Wh@t1$C2L diff --git a/config/shops.json b/config/shops.json index dc0e3b46..1e141bc9 100644 --- a/config/shops.json +++ b/config/shops.json @@ -1,18 +1,7 @@ { "data": [ { - "lookup": "chromis-1.zsai.ws", - "value": { - "key": "877eY5iPvpVzaYnIkc2FgIy0U85FtqpTpQGqoM/RCG0=\n", - "iv": "qSVQaKzOm3TYmRP3DhHdig==\n" - } - }, - { - "lookup": "gw2a-13.zsai.dev", - "value": { - "key": "R0uRkGlvCD5DGaPV4SkhGlwaMR0ohYBBmNna+tpRXMc=\n", - "iv": "AP5iuLM36oJmnvLsWCo9+Q==\n" - } + } ] } From c1b112636cecf3190c2ab35882ec316c1fe51602 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 5 Mar 2018 13:54:52 +0630 Subject: [PATCH 92/98] update license --- config/license.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 config/license.yml diff --git a/config/license.yml b/config/license.yml new file mode 100644 index 00000000..40543709 --- /dev/null +++ b/config/license.yml @@ -0,0 +1,15 @@ +iv_key: KoQBUN3M44TXHKj9dlZk7w== +shop_name: sx_license_test +email: aungmyo.zaw@code2lab.com +telephone: 0099404923 +fax: 49494949432 +address: Yangon +dbhost: 8j/QXxl+Gpvz0/9BXMP8Uw== +dbschema: Egf4CfJLOWC8qaNVS3NyXQ== +dbusername: BbdbUXyfb8O0g61L8Bo1hQ== +dbpassword: lGn1m2/5wouc1J+1qDKuAQ== +api_token: MWEvlKvhPjwJNvhAjdgYCwWJxMaaFpDoMtgmuvCs +app_token: rXkavjsHhCeOnTuOBSZhKBmudIJpFWHQxtSzSO +plan_sku: 4JRlspPt+MaMfNIpk9tZHw== +renewable_date: e5ZXSh24RJBzqIxNCTPrtQ== +plan_name: qZgXEt61vcVSzD3d63NCHA== From 2d62750caafeefbd4e330da8a3a7e8f862a53559 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 5 Mar 2018 14:04:38 +0630 Subject: [PATCH 93/98] update delete license --- config/license.yml | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 config/license.yml diff --git a/config/license.yml b/config/license.yml deleted file mode 100644 index 40543709..00000000 --- a/config/license.yml +++ /dev/null @@ -1,15 +0,0 @@ -iv_key: KoQBUN3M44TXHKj9dlZk7w== -shop_name: sx_license_test -email: aungmyo.zaw@code2lab.com -telephone: 0099404923 -fax: 49494949432 -address: Yangon -dbhost: 8j/QXxl+Gpvz0/9BXMP8Uw== -dbschema: Egf4CfJLOWC8qaNVS3NyXQ== -dbusername: BbdbUXyfb8O0g61L8Bo1hQ== -dbpassword: lGn1m2/5wouc1J+1qDKuAQ== -api_token: MWEvlKvhPjwJNvhAjdgYCwWJxMaaFpDoMtgmuvCs -app_token: rXkavjsHhCeOnTuOBSZhKBmudIJpFWHQxtSzSO -plan_sku: 4JRlspPt+MaMfNIpk9tZHw== -renewable_date: e5ZXSh24RJBzqIxNCTPrtQ== -plan_name: qZgXEt61vcVSzD3d63NCHA== From 4b26c7617cc5028fb19b5ee718119e3b779b4598 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 5 Mar 2018 14:10:38 +0630 Subject: [PATCH 94/98] update remove byebyg --- app/controllers/install_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index 5aa7af06..1ff003db 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -35,7 +35,6 @@ class InstallController < BaseController if response[:status] redirect_to root_url, notice: response["message"] else - byebug redirect_to activate_path, notice: response["message"] end end From 5eec1ad37714329f956278af1f47228207ef1a42 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 5 Mar 2018 14:12:30 +0630 Subject: [PATCH 95/98] check product sale query --- app/models/sale.rb | 9 +++++---- app/views/reports/product_sale/index.html.erb | 13 ++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 4a12715f..32f196ff 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -851,10 +851,10 @@ def self.get_menu_item_query(order_by) query = MenuItem.unscoped.select("acc.id as account_id, acc.title as account_name, mii.item_instance_code as item_code, " + - "(CASE WHEN si.qty != '' THEN SUM(si.qty) ELSE 0 END) as total_item," + + "(CASE WHEN si.qty IS NOT NULL THEN SUM(si.qty) ELSE 0 END) as total_item," + "(CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END) as unit_price," + - "(CASE WHEN (si.qty * si.unit_price) > 0 THEN (si.qty * si.unit_price) ELSE 0 END) as grand_total," + - "mii.price as unit_price, mii.item_instance_name as product_name, + "(CASE WHEN si.qty IS NOT NULL THEN (SUM(si.qty) * si.unit_price) ELSE 0 END) as grand_total," + + "mii.price as unit_price, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE mii.item_instance_name END) as product_name, mc.name as" + " menu_category_name,mc.id as menu_category_id, si.remark as status_type, si.price as price ") @@ -863,7 +863,8 @@ def self.get_menu_item_query(order_by) " LEFT JOIN accounts acc ON acc.id = menu_items.account_id" + " LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" + " LEFT JOIN sales s ON s.sale_id = si.sale_id") - .group("mc.id, mii.item_instance_name, (CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END)") + .where("(CASE WHEN s.sale_status IS NOT NULL THEN s.sale_status='completed' ELSE 1 END)") + .group("mc.id, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE mii.item_instance_name END)") .order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}") end #product sale report query diff --git a/app/views/reports/product_sale/index.html.erb b/app/views/reports/product_sale/index.html.erb index a62e0d73..ffad886a 100755 --- a/app/views/reports/product_sale/index.html.erb +++ b/app/views/reports/product_sale/index.html.erb @@ -47,7 +47,6 @@ <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.unit_price") %> <%= t("views.right_panel.detail.total") %> - <%= t("views.right_panel.detail.remark") %> @@ -59,24 +58,28 @@ <% total_qty = 0 %> <% @sale_data.each do |sale| %> + <% grand_total += sale.grand_total %> <% if sale.status_type != "Discount" && sale.status_type != "foc" total_qty += sale.total_item - grand_total += sale.grand_total end %> <% if sale.status_type == "foc" && sale.price > 0 total_qty += sale.total_item - grand_total += sale.grand_total end %>   + <% if !cate_arr.include?(sale.menu_category_id) %> <%= sale.menu_category_name %> + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + <% cate_arr = Array.new %> +   + <% end %> <%= sale.item_code rescue '-' %> <%= sale.product_name rescue '-' %> <%= sale.total_item rescue '-' %> <%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> - <%= sale.status_type rescue '' %> @@ -86,7 +89,7 @@ Total <%= total_qty %> - <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> + <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> <% end %> From 9f59962b8f93b36560a9a032940e4dcfff1dbcdb Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 5 Mar 2018 14:46:50 +0630 Subject: [PATCH 96/98] update addorder js --- app/assets/javascripts/addorder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index de1024ea..69ac19d4 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -761,7 +761,7 @@ $(function() { type = window.location.href.indexOf("quick_service"); - if (type != 'true') { + if (type != -1) { type = 'quick_service' var table_type = $('#table_type').text(); var table_id = $('#table_id').val(); From dfb80de435f41dc22c839dc071377a68b9f3628b Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 5 Mar 2018 14:49:01 +0630 Subject: [PATCH 97/98] change product account --- app/models/product.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/product.rb b/app/models/product.rb index 2d8cc013..9482b376 100755 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -5,11 +5,18 @@ class Product < ApplicationRecord mount_uploader :image_path, ProductImageUploader def self.search_by_product_code(item_code) + account = Account.where('title','like','%Product%').first() + if !account.nil? + account_id = account.id + else + account_id = 1 + end + menu_item_hash = Hash.new mt_instance = Product.find_by_item_code(item_code) if (!mt_instance.nil?) menu_item_hash[:type] = 'Product' - menu_item_hash[:account_id] = 3 + menu_item_hash[:account_id] = account_id menu_item_hash[:item_code] = mt_instance.item_code menu_item_hash[:item_instance_code] = mt_instance.item_code menu_item_hash[:name] = mt_instance.name.to_s From e252c0acc3719fbc8a13f1fffbfa7fe258962906 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 5 Mar 2018 15:00:18 +0630 Subject: [PATCH 98/98] check product account --- app/models/product.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index 9482b376..3256fe17 100755 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -5,13 +5,13 @@ class Product < ApplicationRecord mount_uploader :image_path, ProductImageUploader def self.search_by_product_code(item_code) - account = Account.where('title','like','%Product%').first() + account = Account.find_by_title('Product') if !account.nil? account_id = account.id else account_id = 1 end - + menu_item_hash = Hash.new mt_instance = Product.find_by_item_code(item_code) if (!mt_instance.nil?)