From 94a65a749f4e756b2b6b28b4517ac1c1c21dbee4 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 25 Jul 2018 17:19:00 +0630 Subject: [PATCH 01/15] change tax profile structure --- app/controllers/crm/customers_controller.rb | 4 +- .../origami/customers_controller.rb | 4 +- .../origami/request_bills_controller.rb | 122 +++++++++--------- .../settings/tax_profiles_controller.rb | 12 +- app/models/sale.rb | 4 +- app/views/origami/payments/show.html.erb | 8 +- 6 files changed, 85 insertions(+), 69 deletions(-) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 70f5a617..a64d7af4 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -39,7 +39,9 @@ class Crm::CustomersController < BaseCrmController @membership_types = Lookup.collection_of("member_group_type") - @taxes = TaxProfile.where(:group_type => 'cashier') + # @taxes = TaxProfile.where(:group_type => 'cashier') + @taxes = TaxProfile.unscoped.select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") + .order("group_type ASC,order_by ASC") @filter = filter diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 8e002532..0eee0400 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -87,7 +87,9 @@ class Origami::CustomersController < BaseOrigamiController @crm_customer = Customer.new @count_customer = Customer.count_customer - @taxes = TaxProfile.where(:group_type => 'cashier') + # @taxes = TaxProfile.where(:group_type => 'cashier') + @taxes = TaxProfile.unscoped.select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") + .order("group_type ASC,order_by ASC") # if flash["errors"] # @crm_customer.valid? # end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 961fc855..58aa978d 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -12,76 +12,82 @@ class Origami::RequestBillsController < ApplicationController sale_order=SaleOrder.new if !ShiftSale.current_shift.nil? - order_id = params[:id] # order_id - bk_order = BookingOrder.find_by_order_id(order_id) - order = Order.find(order_id) - check_booking = Booking.find_by_booking_id(bk_order.booking_id) - if check_booking.dining_facility_id.to_i > 0 - table = DiningFacility.find(check_booking.dining_facility_id) - else - table = nil - end + tax_profiles = TaxProfile.unscoped.where("group_type='cashier'").pluck(:id) + customers = Customer.find('CUS-000000000002') + + puts "data => " + puts tax_profiles.to_json + puts customers.tax_profiles.to_json + # order_id = params[:id] # order_id + # bk_order = BookingOrder.find_by_order_id(order_id) + # order = Order.find(order_id) + # check_booking = Booking.find_by_booking_id(bk_order.booking_id) + # if check_booking.dining_facility_id.to_i > 0 + # table = DiningFacility.find(check_booking.dining_facility_id) + # else + # table = nil + # end - if check_booking.sale_id.nil? - # Create Sale if it doesn't exist - @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source) - @sale_data = Sale.find_by_sale_id(@sale_id) - @sale_items = SaleItem.where("sale_id=?",@sale_id) + # if check_booking.sale_id.nil? + # # Create Sale if it doesn't exist + # @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source) + # @sale_data = Sale.find_by_sale_id(@sale_id) + # @sale_items = SaleItem.where("sale_id=?",@sale_id) - # in-duty update - in_duties = InDuty.where("booking_id=?",bk_order.booking_id) - if !in_duties.empty? - in_duties.each do |in_duty| - induty = InDuty.find(in_duty.id) - induty.sale_id = @sale_id - induty.save - end - end - else - @sale_data = Sale.find_by_sale_id(check_booking.sale_id) - @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) - end + # # in-duty update + # in_duties = InDuty.where("booking_id=?",bk_order.booking_id) + # if !in_duties.empty? + # in_duties.each do |in_duty| + # induty = InDuty.find(in_duty.id) + # induty.sale_id = @sale_id + # induty.save + # end + # end + # else + # @sale_data = Sale.find_by_sale_id(check_booking.sale_id) + # @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) + # end - # Bind shift sale id to sale - # @sale_data.shift_sale_id = shift.id - # @sale_data.save + # # Bind shift sale id to sale + # # @sale_data.shift_sale_id = shift.id + # # @sale_data.save - action_by = current_user.name - type = "REQUEST_BILL" + # action_by = current_user.name + # type = "REQUEST_BILL" - remark = "Request bill Receipt No #{@sale_data.receipt_no}" - sale_audit = SaleAudit.record_audit_sale(@sale_data.sale_id,remark,action_by,type ) + # remark = "Request bill Receipt No #{@sale_data.receipt_no}" + # sale_audit = SaleAudit.record_audit_sale(@sale_data.sale_id,remark,action_by,type ) - # Promotion Activation - Promotion.promo_activate(@sale) + # # Promotion Activation + # Promotion.promo_activate(@sale) - #bill channel - if ENV["SERVER_MODE"] == 'cloud' - from = request.subdomain + "." + request.domain - else - from = "" - end + # #bill channel + # if ENV["SERVER_MODE"] == 'cloud' + # from = request.subdomain + "." + request.domain + # else + # from = "" + # end - ActionCable.server.broadcast "bill_channel",table: table, from: from - if order.source == "quick_service" - result = {:status=> @status, :data => @sale.sale_id } - render :json => result.to_json - else + # ActionCable.server.broadcast "bill_channel",table: table, from: from + # if order.source == "quick_service" + # result = {:status=> @status, :data => @sale.sale_id } + # render :json => result.to_json + # else - if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server - printer = PrintSetting.find_by_unique_code("CheckInOutPdf") - unique_code = "CheckInOutPdf" - booking = Booking.find_by_booking_id(bk_order.booking_id) + # printer = PrintSetting.find_by_unique_code("CheckInOutPdf") + # unique_code = "CheckInOutPdf" + # booking = Booking.find_by_booking_id(bk_order.booking_id) - # print when complete click - order_queue_printer = Printer::OrderQueuePrinter.new(printer) + # # print when complete click + # order_queue_printer = Printer::OrderQueuePrinter.new(printer) - if !printer.nil? - order_queue_printer.print_check_in_out(printer, booking, table) - end - end - end + # if !printer.nil? + # order_queue_printer.print_check_in_out(printer, booking, table) + # end + # end + # end else @status = false @error_message = "No Current Open Shift for This Employee" diff --git a/app/controllers/settings/tax_profiles_controller.rb b/app/controllers/settings/tax_profiles_controller.rb index 75e4343e..7357e21d 100755 --- a/app/controllers/settings/tax_profiles_controller.rb +++ b/app/controllers/settings/tax_profiles_controller.rb @@ -76,9 +76,15 @@ class Settings::TaxProfilesController < ApplicationController # DELETE /settings/tax_profiles/1 # DELETE /settings/tax_profiles/1.json def destroy - @settings_tax_profile.destroy - flash[:notice] = 'Tax profile was successfully destroyed.' - render :json => {:status=> "Success", :url => settings_tax_profiles_url }.to_json + customers = Customer.where("tax_profiles LIKE '%#{@settings_tax_profile.id}%'") + if customers.nil? || customers.empty? + @settings_tax_profile.destroy + flash[:notice] = 'Tax profile was successfully destroyed.' + render :json => {:status=> "Success", :url => settings_tax_profiles_url }.to_json + else + flash[:error] = 'Tax profile could not destroy! This record is using in somewhere.' + render :json => {:status=> "Error", :url => settings_tax_profiles_url }.to_json + end # respond_to do |format| # format.html { redirect_to settings_tax_profiles_url, notice: 'Tax profile was successfully destroyed.' } # format.json { head :no_content } diff --git a/app/models/sale.rb b/app/models/sale.rb index 63189759..1504f947 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1498,7 +1498,7 @@ end else query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) end - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' @@ -1508,7 +1508,7 @@ end else query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) end - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') else shift = ShiftSale.current_open_shift(current_user.id) diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 6cb85113..195719bd 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -401,14 +401,14 @@ <% if current_login_employee.role == "cashier" %> - <% if @other_payment < 0 && @sale_payment.nil? %> + <% if @other_payment <= 0 && @sale_payment.nil? %> <%if @sale_data.total_discount == 0 %> FOC <% end %> <%end %> <% if @sale_payment.nil? %> Void - <% if @other_payment < 0 %> + <% if @other_payment <= 0 %> <%if @sale_data.total_discount == 0 %> Waste Spoile @@ -416,14 +416,14 @@ <% end %> <% end %> <% else %> - <% if @other_payment < 0 && @sale_payment.nil?%> + <% if @other_payment <= 0 && @sale_payment.nil?%> <%if @sale_data.total_discount == 0 %> From fd44a57689c301466db315f7512298d6f7e4ec98 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 26 Jul 2018 11:10:54 +0630 Subject: [PATCH 02/15] check tax profile --- .../origami/request_bills_controller.rb | 24 +++++++++++++++--- app/models/sale.rb | 25 +++++++++++++++---- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 58aa978d..521b1eaf 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -12,12 +12,23 @@ class Origami::RequestBillsController < ApplicationController sale_order=SaleOrder.new if !ShiftSale.current_shift.nil? - tax_profiles = TaxProfile.unscoped.where("group_type='cashier'").pluck(:id) - customers = Customer.find('CUS-000000000002') + tax_data = TaxProfile.unscoped.where("group_type='cashier'").pluck(:id) + customer = Customer.find('CUS-000000000001') puts "data => " - puts tax_profiles.to_json - puts customers.tax_profiles.to_json + puts tax_data + puts customer.tax_profiles + arr_data = [] + tax_data.each do |value1| + puts JSON.stringify(customer.tax_profiles) + if customer.include? value1 + arr_data << value1 + end + end + puts "unique => " + puts arr_data + # tax_profiles = TaxProfile.unscoped.where("id in ?",arr_data) + # puts tax_profiles.to_json # order_id = params[:id] # order_id # bk_order = BookingOrder.find_by_order_id(order_id) # order = Order.find(order_id) @@ -93,6 +104,11 @@ class Origami::RequestBillsController < ApplicationController @error_message = "No Current Open Shift for This Employee" end + def difference(other) + h = other.each_with_object(Hash.new(0)) { |e,h| h[e] += 1 } + reject { |e| h[e] > 0 && h[e] -= 1 } + end + # Not Use for these printed bill cannot give customer # unique_code = "ReceiptBillPdf" # #shop detail diff --git a/app/models/sale.rb b/app/models/sale.rb index a2a58ff9..3e7d053b 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -512,13 +512,23 @@ class Sale < ApplicationRecord total_tax_amount = 0 tax_incl_exec = "exclusive" #tax_profile - list by order_by - tax_profiles = TaxProfile.all.order("order_by asc") - - customer = Customer.find(self.customer_id) + # tax_profiles = TaxProfile.all.order("order_by asc") if order_source.to_s == "emenu" order_source = "cashier" end + tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id) + customer = Customer.find(self.customer_id).tax_profiles + + arr_tax = [] + + arr_tax = customer - tax_data + + if !arr_tax.empty? + tax_profiles = TaxProfile.unscoped.where("id in ?",arr_tax) + else + tax_profiles = TaxProfile.unscoped.where("group_type=?",order_source) + end #Create new tax records tax_profiles.each do |tax| if tax.group_type.to_s == order_source.to_s @@ -552,8 +562,8 @@ class Sale < ApplicationRecord # end end end - self.tax_type = tax_incl_exec - self.total_tax = total_tax_amount + self.tax_type = tax_incl_exec + self.total_tax = total_tax_amount end def product_get_unit_price(item_code) @@ -2774,6 +2784,11 @@ def self.get_sale_data_for_other_payment_credit(sale_id) return query end +def difference(other) + h = other.each_with_object(Hash.new(0)) { |e,h| h[e] += 1 } + reject { |e| h[e] > 0 && h[e] -= 1 } +end + private def generate_custom_id From ca14b1e399dd0aeb41a420a9250b9db8225e48a7 Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 30 Jul 2018 16:10:17 +0630 Subject: [PATCH 03/15] change credit payment query for dashboard and daily sales --- app/controllers/home_controller.rb | 7 +++-- app/models/sale.rb | 28 ++++++++++--------- app/models/sale_payment.rb | 2 +- .../order_reservations/index.html.erb | 16 ++++++----- .../order_reservations/show.html.erb | 16 ++++++----- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 7d87ea8f..0d155b9e 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -126,8 +126,11 @@ class HomeController < ApplicationController if !employee_sales.nil? employee_sales.each do |emp| emp_data = [] - emp_data.push([emp.e_name, emp.payment_amount]) - @employee_sales.push({'name' => emp.payment_method, 'data' => emp_data}) + if emp.payment_amount > 0 + emp_data.push([emp.e_name, emp.payment_amount]) + + @employee_sales.push({'name' => emp.payment_method, 'data' => emp_data}) + end end end @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance) diff --git a/app/models/sale.rb b/app/models/sale.rb index ccd25fc5..db9ca306 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -725,12 +725,13 @@ class Sale < ApplicationRecord def self.daily_sales_list(from,to) - sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) - FROM sale_payments - INNER JOIN sale_audits sa - ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id - INNER JOIN sales ON sa.sale_id = sales.sale_id - WHERE sales.sale_status='completed' AND sales.receipt_date between '#{from}' and '#{to}'" + sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN + (SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount)) ELSE 0 END) + FROM sale_payments + INNER JOIN sale_audits sa ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id + INNER JOIN sales s ON s.sale_id=sa.sale_id + WHERE s.sale_status='completed' + AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') = DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d')" payments_total = Sale.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount, @@ -747,7 +748,7 @@ def self.daily_sales_list(from,to) (CASE WHEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end)) > 0 THEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) - (#{sub_query})) ELSE 0 END) as credit_amount, SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") - .joins(" left join sale_payments on sale_payments.sale_id = sales.sale_id") + .joins(" join sale_payments on sale_payments.sale_id = sales.sale_id") .where("sale_status = ? AND sales.receipt_date between ? and ? ", 'completed', from, to) .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')") @@ -1113,7 +1114,8 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter) INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id WHERE sale_audits.sale_id = s.sale_id" - sub_query1 = "SELECT (CASE WHEN SUM(payment_amount) > 0 THEN SUM(payment_amount) ELSE 0 END) + sub_query1 = "SELECT (CASE WHEN SUM(payment_amount) > 0 THEN SUM(payment_amount) - + (SUM(payment_amount) - (SELECT SUM(payment_amount) FROM sale_payments WHERE payment_method='creditnote' AND sale_id=s.sale_id)) ELSE 0 END) FROM `sale_payments` INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id WHERE sale_audits.sale_id = s.sale_id" @@ -1498,7 +1500,7 @@ end else query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) end - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' @@ -1508,7 +1510,7 @@ end else query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) end - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') else shift = ShiftSale.current_open_shift(current_user.id) @@ -1551,7 +1553,7 @@ end def self.employee_sales(today,current_user,from,to,from_time,to_time) #sub query for credit payment - sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) AS payment_amount + sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount) ELSE 0 END) AS payment_amount FROM sale_payments INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id INNER JOIN sales ON sale_audits.sale_id = sales.sale_id @@ -1741,7 +1743,7 @@ end end def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - sub_query = SalePayment.select("(CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) as total_credit_payment") + sub_query = SalePayment.select("(CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount) ELSE 0 END) as total_credit_payment") .joins(" JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id") .joins(" JOIN sales ON sale_audits.sale_id = sales.sale_id") .where("sales.sale_status='completed'") @@ -1969,7 +1971,7 @@ end time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" end - sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) + sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount) ELSE 0 END) FROM sale_payments INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id INNER JOIN sales ON sale_audits.sale_id = sales.sale_id diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 93395250..41ec593a 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -21,7 +21,7 @@ class SalePayment < ApplicationRecord invoice_sale_payments = invoice.sale_payments amount_due = invoice.grand_total end - + invoice_sale_payments.each do |payment| if (payment.payment_status == "paid" ) amount_due = amount_due - payment.payment_amount diff --git a/app/views/transactions/order_reservations/index.html.erb b/app/views/transactions/order_reservations/index.html.erb index 7709e402..f8063fd2 100644 --- a/app/views/transactions/order_reservations/index.html.erb +++ b/app/views/transactions/order_reservations/index.html.erb @@ -116,13 +116,15 @@ discount_amount = order_reservation.discount_amount delivery_fee = order_reservation.delivery_fee ? order_reservation.delivery_fee : 0.0 convenience_charge = order_reservation.convenience_charge - JSON.parse(order_reservation.taxes).each do |tax_data| - if tax_data[0] == "delivery_tax" - delivery_tax = tax_data[1] - elsif tax_data[0] == "convenience_tax" - convenience_tax = tax_data[1] - elsif tax_data[0] == "commercial_tax" - commercial_tax = tax_data[1] + if !JSON.parse(order_reservation.taxes).empty? + JSON.parse(order_reservation.taxes).each do |tax_data| + if tax_data[0] == "delivery_tax" + delivery_tax = tax_data[1] + elsif tax_data[0] == "convenience_tax" + convenience_tax = tax_data[1] + elsif tax_data[0] == "commercial_tax" + commercial_tax = tax_data[1] + end end end %> diff --git a/app/views/transactions/order_reservations/show.html.erb b/app/views/transactions/order_reservations/show.html.erb index ed6d2da8..7ab06b0c 100755 --- a/app/views/transactions/order_reservations/show.html.erb +++ b/app/views/transactions/order_reservations/show.html.erb @@ -104,13 +104,15 @@ discount_amount = @order_reservation.discount_amount delivery_fee = @order_reservation.delivery_fee ? @order_reservation.delivery_fee : 0.0 convenience_charge = @order_reservation.convenience_charge - JSON.parse(@order_reservation.taxes).each do |tax_data| - if tax_data[0] == "delivery_tax" - delivery_tax = tax_data[1] - elsif tax_data[0] == "convenience_tax" - convenience_tax = tax_data[1] - elsif tax_data[0] == "commercial_tax" - commercial_tax = tax_data[1] + if !JSON.parse(order_reservation.taxes).empty? + JSON.parse(@order_reservation.taxes).each do |tax_data| + if tax_data[0] == "delivery_tax" + delivery_tax = tax_data[1] + elsif tax_data[0] == "convenience_tax" + convenience_tax = tax_data[1] + elsif tax_data[0] == "commercial_tax" + commercial_tax = tax_data[1] + end end end total_discount_amount += discount_amount.to_f From 01783c270766e5d8df06cff0608dfd02426df51a Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 30 Jul 2018 17:20:04 +0630 Subject: [PATCH 04/15] add transaction fee for order reservation --- app/views/reports/order_reservation/index.html.erb | 7 +++++++ app/views/reports/order_reservation/index.xls.erb | 7 +++++++ config/locales/en.yml | 1 + config/locales/mm.yml | 1 + db/migrate/20180406080240_create_order_reservations.rb | 1 + 5 files changed, 17 insertions(+) diff --git a/app/views/reports/order_reservation/index.html.erb b/app/views/reports/order_reservation/index.html.erb index b59dc3db..439e7772 100755 --- a/app/views/reports/order_reservation/index.html.erb +++ b/app/views/reports/order_reservation/index.html.erb @@ -57,6 +57,7 @@ <%= t("views.right_panel.detail.commercial_tax") %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> <%= t("views.right_panel.detail.grand_total") %> + <%= t("views.right_panel.detail.transaction_fee") %> @@ -88,6 +89,7 @@ total_tax = 0.0 total_amount = 0.0 grand_total = 0.0 + transaction_fee = 0.0 %> <% unless @order_reservation_data.blank? %> <% @order_reservation_data.each do |order_reservation| %> @@ -117,6 +119,9 @@ total_amount += order_reservation.total_amount.to_f grand_total += order_reservation.grand_total.to_f %> + <% if order_reservation.transaction_fee && order_reservation.transaction_fee > 0 + transaction_fee += order_reservation.transaction_fee.to_f + end %> <% if order_reservation.provider == 'pick_up' provider = "Pick-Up" @@ -149,6 +154,7 @@ <%= number_with_precision(commercial_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> + <%= number_with_precision(order_reservation.transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> <% end end %> @@ -164,6 +170,7 @@ <%= number_with_precision(total_commercial_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_with_precision(transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> diff --git a/app/views/reports/order_reservation/index.xls.erb b/app/views/reports/order_reservation/index.xls.erb index d5617225..bb444043 100755 --- a/app/views/reports/order_reservation/index.xls.erb +++ b/app/views/reports/order_reservation/index.xls.erb @@ -40,6 +40,7 @@ <%= t("views.right_panel.detail.commercial_tax") %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> <%= t("views.right_panel.detail.grand_total") %> + <%= t("views.right_panel.detail.transaction_fee") %> @@ -61,6 +62,7 @@ total_tax = 0.0 total_amount = 0.0 grand_total = 0.0 + transaction_fee = 0.0 %> <% unless @order_reservation_data.blank? %> <% @order_reservation_data.each do |order_reservation| %> @@ -91,6 +93,9 @@ total_amount += order_reservation.total_amount.to_f grand_total += order_reservation.grand_total.to_f %> + <% if order_reservation.transaction_fee && order_reservation.transaction_fee > 0 + transaction_fee += order_reservation.transaction_fee.to_f + end %> <% if order_reservation.provider == 'pick_up' provider = "Pick-Up" @@ -123,6 +128,7 @@ <%= commercial_tax rescue '0.0'%> <%= order_reservation.total_tax rescue '0.0'%> <%= order_reservation.grand_total rescue '0.0' %> + <%= order_reservation.transaction_fee rescue '0.0' %> <% end end %> @@ -138,6 +144,7 @@ <%= total_commercial_tax rescue '0.0'%> <%= total_tax rescue '0.0'%> <%= grand_total rescue '0.0'%> + <%= transaction_fee rescue '0.0'%> diff --git a/config/locales/en.yml b/config/locales/en.yml index 66e35892..689a1890 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -491,6 +491,7 @@ en: induty_report: "Induty Report" in_time: "In Time" out_time: "Out Time" + transaction_fee: "Transaction Fee" code_txt: "code " charge_txt: "charge" diff --git a/config/locales/mm.yml b/config/locales/mm.yml index 3aa5cb09..111cca55 100644 --- a/config/locales/mm.yml +++ b/config/locales/mm.yml @@ -485,6 +485,7 @@ mm: induty_report: "Induty Report" in_time: "In Time" out_time: "Out Time" + transaction_fee: "Transaction Fee" code_txt: "ကုတ်ဒ် " charge_txt: "ကောက်ခံသည်" diff --git a/db/migrate/20180406080240_create_order_reservations.rb b/db/migrate/20180406080240_create_order_reservations.rb index a343958f..f5a46dd2 100644 --- a/db/migrate/20180406080240_create_order_reservations.rb +++ b/db/migrate/20180406080240_create_order_reservations.rb @@ -19,6 +19,7 @@ class CreateOrderReservations < ActiveRecord::Migration[5.1] t.decimal :discount_amount, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :convenience_charge, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :grand_total, :precision => 10, :scale => 2, :null => false, :default => 0.00 + t.decimal :transaction_fee, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.string :status, :null => false, :default => "new" t.string :order_remark t.string :remark From 186bc090dfc77d28debf853d94d54096a63d6946 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 2 Aug 2018 11:53:29 +0630 Subject: [PATCH 05/15] change query for credit payment and add sound effect for ordering --- .../origami/bank_integration.coffee | 3 - app/assets/javascripts/application.js | 1 + app/assets/javascripts/channels/order.js | 4 +- .../javascripts/channels/sound_effect.js | 36 ++++++ app/channels/sound_effect_channel.rb | 10 ++ .../api/sound_effect_controller.rb | 30 +++++ .../origami/payments_controller.rb | 2 +- app/models/order_reservation.rb | 1 + app/models/sale.rb | 116 +++++++++++++----- app/models/sale_payment.rb | 15 ++- app/views/home/show.html.erb | 4 +- config/initializers/assets.rb | 4 +- config/routes.rb | 2 + 13 files changed, 185 insertions(+), 43 deletions(-) delete mode 100644 app/assets/javascripts/app/controllers/origami/bank_integration.coffee create mode 100644 app/assets/javascripts/channels/sound_effect.js create mode 100644 app/channels/sound_effect_channel.rb create mode 100644 app/controllers/api/sound_effect_controller.rb diff --git a/app/assets/javascripts/app/controllers/origami/bank_integration.coffee b/app/assets/javascripts/app/controllers/origami/bank_integration.coffee deleted file mode 100644 index 24f83d18..00000000 --- a/app/assets/javascripts/app/controllers/origami/bank_integration.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index c6247962..54b1996e 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -28,6 +28,7 @@ //= require raphael/raphael.min //= require Chart.bundle //= require chartkick +//= require cable //= require fileinput.min.js //= require settings/processing_items //= require BSBMaterial/admin.js diff --git a/app/assets/javascripts/channels/order.js b/app/assets/javascripts/channels/order.js index 9326b2cc..4a9e8a95 100755 --- a/app/assets/javascripts/channels/order.js +++ b/app/assets/javascripts/channels/order.js @@ -5,8 +5,8 @@ App.order = App.cable.subscriptions.create('OrderChannel', { received: function(data) { var hostname = location.hostname.trim(); - console.log(hostname) - console.log(data.from) + // console.log(hostname) + // console.log(data.from) if(data.from == "" || hostname == data.from) { if (data.type == 'order') { diff --git a/app/assets/javascripts/channels/sound_effect.js b/app/assets/javascripts/channels/sound_effect.js new file mode 100644 index 00000000..4b988dda --- /dev/null +++ b/app/assets/javascripts/channels/sound_effect.js @@ -0,0 +1,36 @@ +App.sound_effect = App.cable.subscriptions.create('SoundEffectChannel', { + connected: function() {}, + + disconnected: function() {}, + + received: function(data) { + var hostname = location.hostname.trim(); + if(data.from == "" || hostname == data.from){ + var shop_code = data.shop_code; + var audio = data.audio; + var data = data.data; + + if(data.status){ + var audio = new Audio('/'+audio); // define your audio + audio.play(); + } + + if(data.status && ((data.message != undefined) && (data.message!=""))){ + swal({ + title: 'Information', + text: data.message, + type: 'success', + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function (isConfirm) { + if(isConfirm){ + swal.close(); + } + }); + } + } + } +}); + diff --git a/app/channels/sound_effect_channel.rb b/app/channels/sound_effect_channel.rb new file mode 100644 index 00000000..2b3f3ee6 --- /dev/null +++ b/app/channels/sound_effect_channel.rb @@ -0,0 +1,10 @@ +class SoundEffectChannel < ApplicationCable::Channel + def subscribed + stream_from "sound_effect_channel" + end + + def unsubscribed + stop_all_streams + # Any cleanup needed when channel is unsubscribed + end +end \ No newline at end of file diff --git a/app/controllers/api/sound_effect_controller.rb b/app/controllers/api/sound_effect_controller.rb new file mode 100644 index 00000000..e53e69b9 --- /dev/null +++ b/app/controllers/api/sound_effect_controller.rb @@ -0,0 +1,30 @@ +class Api::SoundEffectController < Api::ApiController + + #sound effect / alarm api for doemal side calling + def sound_effect + shop = Shop.find_by_id(1) + if !shop.nil? + shop_code = shop.shop_code + order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio") + if !order_audio.nil? + audio = order_audio.image + end + else + shop_code = nil + audio = nil + end + + if !shop_code.nil? && !audio.nil? + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain + "." + request.domain + else + from = "" + end + ActionCable.server.broadcast "sound_effect_channel",data: {status: params[:status], message: params[:message]},shop_code: shop_code,from:from,audio:audio + else + render :json => { :status => true, :message => "Something wrongs!" } + end + end + #sound effect / alarm api for doemal side calling + +end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 6447858b..235b5073 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -241,7 +241,7 @@ class Origami::PaymentsController < BaseOrigamiController sale_id = params[:sale_id] @cashier_type = params[:type] if path.include? ("credit_payment") - @sale_payment = SalePayment.get_credit_total_left(sale_id) + @sale_payment = SalePayment.get_credit_amount_due_left(sale_id) end @member_discount = MembershipSetting.find_by_discount(1) diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index a1450444..5fdc9643 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -70,6 +70,7 @@ class OrderReservation < ApplicationRecord order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount] order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge] order_reservation.grand_total = order_reserve[:payment_info][:grand_total] + order_reservation.transaction_fee = order_reserve[:order_info][:transaction_fee] order_reservation.order_remark = order_reserve[:order_info][:order_remark] end if order_reserve[:reservation_info] diff --git a/app/models/sale.rb b/app/models/sale.rb index db9ca306..2634a695 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -82,10 +82,15 @@ class Sale < ApplicationRecord self.tax_type = "exclusive" # set cashier - open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") - current_shift = ShiftSale.current_shift - shift = ShiftSale.current_open_shift(cashier.id) - + if order_source = "emenu" + table = DiningFacility.find(booking.dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first + else + open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") + current_shift = ShiftSale.current_shift + shift = ShiftSale.current_open_shift(cashier.id) + end # set cashier if shift != nil self.cashier_id = cashier.id @@ -1553,16 +1558,33 @@ end def self.employee_sales(today,current_user,from,to,from_time,to_time) #sub query for credit payment - sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount) ELSE 0 END) AS payment_amount - FROM sale_payments - INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - INNER JOIN sales ON sale_audits.sale_id = sales.sale_id - WHERE sales.sale_status='completed'" + outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END + FROM sale_payments + JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id + JOIN sales ON sale_audits.sale_id = sales.sale_id + WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'" + if !from.nil? && !to.nil? if !from_time.nil? && !to_time.nil? - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" + outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" + outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" + end + else + outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" + end + + sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END) + FROM sale_payments + INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id + INNER JOIN sales ON sale_audits.sale_id = sales.sale_id + WHERE sales.sale_status='completed'" + + if !from.nil? && !to.nil? + if !from_time.nil? && !to_time.nil? + sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" + else + sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'" end else sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" @@ -1743,16 +1765,40 @@ end end def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - sub_query = SalePayment.select("(CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount) ELSE 0 END) as total_credit_payment") + outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END + FROM sale_payments + JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id + JOIN sales ON sale_audits.sale_id = sales.sale_id + WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'" + + if !from.nil? && !to.nil? + if !from_time.nil? && !to_time.nil? + outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" + else + outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" + end + else + outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" + end + + sub_query = SalePayment.select("(CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END) as total_credit_payment") .joins(" JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id") .joins(" JOIN sales ON sale_audits.sale_id = sales.sale_id") .where("sales.sale_status='completed'") + if !from.nil? && !to.nil? + if !from_time.nil? && !to_time.nil? + sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'") + else + sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'") + end + else + sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'") + end + if !from.nil? && !to.nil? if current_user.nil? if !from_time.nil? && !to_time.nil? - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'") - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1760,7 +1806,6 @@ end query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) end else - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'") query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1771,8 +1816,6 @@ end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' if !from_time.nil? && !to_time.nil? - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'") - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1780,7 +1823,6 @@ end query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) end else - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'") query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1792,7 +1834,6 @@ end shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? if !from_time.nil? && !to_time.nil? - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'") query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and s.shift_sale_id=?',from,to,from_time,to_time,shift.id) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1800,7 +1841,6 @@ end query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) end else - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'") query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',from,to,shift.id) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1812,7 +1852,6 @@ end end end else - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{today}' AND '#{today}'") if current_user.nil? query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") @@ -1971,16 +2010,41 @@ end time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" end - sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount) ELSE 0 END) + outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END + FROM sale_payments + JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id + JOIN sales ON sale_audits.sale_id = sales.sale_id + WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'" + + if !from.nil? && !to.nil? + if !from_time.nil? && !to_time.nil? + outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" + else + outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" + end + else + outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" + end + + sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END) FROM sale_payments INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id INNER JOIN sales ON sale_audits.sale_id = sales.sale_id WHERE sales.sale_status='completed'" + if !from.nil? && !to.nil? + if !from_time.nil? && !to_time.nil? + sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" + else + sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'" + end + else + sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" + end + if !from.nil? && !to.nil? if current_user.nil? if !from_time.nil? && !to_time.nil? - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" 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(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? 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" or sp.payment_method="alipay" or sp.payment_method="paymal" or sp.payment_method="dinga" or sp.payment_method="JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time) @@ -1989,7 +2053,6 @@ end end query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first() else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" 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(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to) @@ -2001,7 +2064,6 @@ end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' if !from_time.nil? && !to_time.nil? - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" 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(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time) @@ -2010,7 +2072,6 @@ end end query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first() else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" 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(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to) @@ -2023,7 +2084,6 @@ end shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? if !from_time.nil? && !to_time.nil? - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" 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(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) @@ -2032,7 +2092,6 @@ end end query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first() else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" 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(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and sales.shift_sale_id=?',from,to,shift.id) @@ -2045,7 +2104,6 @@ end end end else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" if current_user.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 41ec593a..3e0ad377 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -16,7 +16,7 @@ class SalePayment < ApplicationRecord #get all payment for this invoices if payment_for invoice_sale_payments = SalePayment.get_sale_payment_for_credit(invoice) - amount_due = SalePayment.get_credit_total_left(self.sale_id)[0] ? SalePayment.get_credit_total_left(self.sale_id)[0].payment_amount.to_f : 0 + amount_due = SalePayment.get_credit_amount_due_left(self.sale_id)[0] ? SalePayment.get_credit_amount_due_left(self.sale_id)[0].payment_amount.to_f : 0 else invoice_sale_payments = invoice.sale_payments amount_due = invoice.grand_total @@ -875,13 +875,22 @@ class SalePayment < ApplicationRecord return query end - def self.get_credit_total_left(sale_id) + def self.get_credit_amount_due_left(sale_id) query = SalePayment.select("(SUM(sale_payments.payment_amount) - (CASE WHEN SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id THEN SUM(sale_payments.payment_amount) ELSE 0 END)) as payment_amount") .joins(" LEFT JOIN sale_audits sa on SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id") .where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{sale_id}'") - .group("sale_payments.sale_id") + return query + end + + def self.get_credit_total_left(sale_id) + query = SalePayment.select("(SUM(sale_payments.payment_amount) - + (SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) AS payment_amount + FROM sale_payments + INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id + WHERE sale_payments.sale_id = '#{sale_id}')) as payment_amount") + .where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{sale_id}'") return query end diff --git a/app/views/home/show.html.erb b/app/views/home/show.html.erb index 4d1096c8..c8fc81a8 100755 --- a/app/views/home/show.html.erb +++ b/app/views/home/show.html.erb @@ -44,8 +44,8 @@ event.preventDefault(); var old_value = $("#login_form_password").val(); var value = $(this).data("value"); - console.log(old_value); - console.log(value); + // console.log(old_value); + // console.log(value); if (value == "CLR") { $("#login_form_password").val(""); } else if (value == "ENT") { diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index bd889f51..cede4a18 100755 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -53,9 +53,7 @@ Rails.application.config.assets.precompile += %w( sx-sidebar.css ) Rails.application.config.assets.precompile += %w( inventory_definitions.css ) Rails.application.config.assets.precompile += %w( inventory.js ) -# --- Customer/ Customer - Crm ---- +# --- Order Reservation/ Order ---- Rails.application.config.assets.precompile += %w( order_reservation.css ) Rails.application.config.assets.precompile += %w( order_reservation.js ) - - diff --git a/config/routes.rb b/config/routes.rb index cb5f742b..2926ab5c 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -91,6 +91,8 @@ scope "(:locale)", locale: /en|mm/ do post "callback/:id" => "order_reservation#update_status" get "get_tax_profile" => "order_reservation#get_tax_profile" end + + post "sound_effect" => "sound_effect#sound_effect" end #--------- Cashier ------------# From 444ecb9c68daee577f984af0f1107bb30f59044b Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 2 Aug 2018 14:13:05 +0630 Subject: [PATCH 06/15] check changable tax on/off settings and customer tax profiles calculation --- README.md | 3 + app/controllers/origami/home_controller.rb | 13 ++ .../origami/payments_controller.rb | 14 ++ .../origami/request_bills_controller.rb | 136 ++++++++---------- app/controllers/origami/rooms_controller.rb | 13 ++ app/controllers/origami/sales_controller.rb | 3 +- app/models/sale.rb | 95 +++++++++--- app/views/origami/home/show.html.erb | 5 +- app/views/origami/payments/show.html.erb | 2 +- app/views/origami/rooms/show.html.erb | 5 +- 10 files changed, 184 insertions(+), 105 deletions(-) diff --git a/README.md b/README.md index bdc4c76b..bdaec79e 100755 --- a/README.md +++ b/README.md @@ -251,6 +251,9 @@ For Dashboard Settings for supervisor and cashier For Customer Settings On/Off 1) settings/lookups => {type:customer_settings, name:create, value: {1 or 0}} +For TaxProfiles On/Off + 1) settings/lookups => {type:changable_tax, name:change, value: {1 or 0}} + * ToDo list 1. Migration diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 46c7e236..44b3e1e3 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -130,6 +130,19 @@ class Origami::HomeController < BaseOrigamiController end end end + + #for changable on/off + @changable_tax = true + lookup_changable_tax = Lookup.collection_of('changable_tax') + if !lookup_changable_tax.empty? + lookup_changable_tax.each do |changable_tax| + if changable_tax[0].downcase == "change" + if changable_tax[1] == '0' + @changable_tax = false + end + end + end + end end def check_emp_access_code diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 235b5073..4db5e225 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -271,6 +271,20 @@ class Origami::PaymentsController < BaseOrigamiController if !@lookup_pdf.nil? @pdf_view = @lookup_pdf.value end + + #for changable on/off + @changable_tax = true + lookup_changable_tax = Lookup.collection_of('changable_tax') + if !lookup_changable_tax.empty? + lookup_changable_tax.each do |changable_tax| + if changable_tax[0].downcase == "change" + if changable_tax[1] == '0' + @changable_tax = false + end + end + end + end + @shop = shop_detail #show shop info @customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'") diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 521b1eaf..961fc855 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -12,103 +12,81 @@ class Origami::RequestBillsController < ApplicationController sale_order=SaleOrder.new if !ShiftSale.current_shift.nil? - tax_data = TaxProfile.unscoped.where("group_type='cashier'").pluck(:id) - customer = Customer.find('CUS-000000000001') - - puts "data => " - puts tax_data - puts customer.tax_profiles - arr_data = [] - tax_data.each do |value1| - puts JSON.stringify(customer.tax_profiles) - if customer.include? value1 - arr_data << value1 - end + order_id = params[:id] # order_id + bk_order = BookingOrder.find_by_order_id(order_id) + order = Order.find(order_id) + check_booking = Booking.find_by_booking_id(bk_order.booking_id) + if check_booking.dining_facility_id.to_i > 0 + table = DiningFacility.find(check_booking.dining_facility_id) + else + table = nil end - puts "unique => " - puts arr_data - # tax_profiles = TaxProfile.unscoped.where("id in ?",arr_data) - # puts tax_profiles.to_json - # order_id = params[:id] # order_id - # bk_order = BookingOrder.find_by_order_id(order_id) - # order = Order.find(order_id) - # check_booking = Booking.find_by_booking_id(bk_order.booking_id) - # if check_booking.dining_facility_id.to_i > 0 - # table = DiningFacility.find(check_booking.dining_facility_id) - # else - # table = nil - # end - # if check_booking.sale_id.nil? - # # Create Sale if it doesn't exist - # @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source) - # @sale_data = Sale.find_by_sale_id(@sale_id) - # @sale_items = SaleItem.where("sale_id=?",@sale_id) + if check_booking.sale_id.nil? + # Create Sale if it doesn't exist + @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source) + @sale_data = Sale.find_by_sale_id(@sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_id) - # # in-duty update - # in_duties = InDuty.where("booking_id=?",bk_order.booking_id) - # if !in_duties.empty? - # in_duties.each do |in_duty| - # induty = InDuty.find(in_duty.id) - # induty.sale_id = @sale_id - # induty.save - # end - # end - # else - # @sale_data = Sale.find_by_sale_id(check_booking.sale_id) - # @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) - # end + # in-duty update + in_duties = InDuty.where("booking_id=?",bk_order.booking_id) + if !in_duties.empty? + in_duties.each do |in_duty| + induty = InDuty.find(in_duty.id) + induty.sale_id = @sale_id + induty.save + end + end + else + @sale_data = Sale.find_by_sale_id(check_booking.sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) + end - # # Bind shift sale id to sale - # # @sale_data.shift_sale_id = shift.id - # # @sale_data.save + # Bind shift sale id to sale + # @sale_data.shift_sale_id = shift.id + # @sale_data.save - # action_by = current_user.name - # type = "REQUEST_BILL" + action_by = current_user.name + type = "REQUEST_BILL" - # remark = "Request bill Receipt No #{@sale_data.receipt_no}" - # sale_audit = SaleAudit.record_audit_sale(@sale_data.sale_id,remark,action_by,type ) + remark = "Request bill Receipt No #{@sale_data.receipt_no}" + sale_audit = SaleAudit.record_audit_sale(@sale_data.sale_id,remark,action_by,type ) - # # Promotion Activation - # Promotion.promo_activate(@sale) + # Promotion Activation + Promotion.promo_activate(@sale) - # #bill channel - # if ENV["SERVER_MODE"] == 'cloud' - # from = request.subdomain + "." + request.domain - # else - # from = "" - # end + #bill channel + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain + "." + request.domain + else + from = "" + end - # ActionCable.server.broadcast "bill_channel",table: table, from: from - # if order.source == "quick_service" - # result = {:status=> @status, :data => @sale.sale_id } - # render :json => result.to_json - # else + ActionCable.server.broadcast "bill_channel",table: table, from: from + if order.source == "quick_service" + result = {:status=> @status, :data => @sale.sale_id } + render :json => result.to_json + else - # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" #no print in cloud server - # printer = PrintSetting.find_by_unique_code("CheckInOutPdf") - # unique_code = "CheckInOutPdf" - # booking = Booking.find_by_booking_id(bk_order.booking_id) + printer = PrintSetting.find_by_unique_code("CheckInOutPdf") + unique_code = "CheckInOutPdf" + booking = Booking.find_by_booking_id(bk_order.booking_id) - # # print when complete click - # order_queue_printer = Printer::OrderQueuePrinter.new(printer) + # print when complete click + order_queue_printer = Printer::OrderQueuePrinter.new(printer) - # if !printer.nil? - # order_queue_printer.print_check_in_out(printer, booking, table) - # end - # end - # end + if !printer.nil? + order_queue_printer.print_check_in_out(printer, booking, table) + end + end + end else @status = false @error_message = "No Current Open Shift for This Employee" end - def difference(other) - h = other.each_with_object(Hash.new(0)) { |e,h| h[e] += 1 } - reject { |e| h[e] > 0 && h[e] -= 1 } - end - # Not Use for these printed bill cannot give customer # unique_code = "ReceiptBillPdf" # #shop detail diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index c833c7dd..abdd8842 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -154,6 +154,19 @@ class Origami::RoomsController < BaseOrigamiController end end end + + #for changable on/off + @changable_tax = true + lookup_changable_tax = Lookup.collection_of('changable_tax') + if !lookup_changable_tax.empty? + lookup_changable_tax.each do |changable_tax| + if changable_tax[0].downcase == "change" + if changable_tax[1] == '0' + @changable_tax = false + end + end + end + end end end diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index 876a8ed3..b9cc40ec 100755 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -25,6 +25,7 @@ class Origami::SalesController < BaseOrigamiController def add_to_existing_invoice dining = params[:dining_id] sale_id = params[:sale_id] + tax_type = params[:tax_type] table = DiningFacility.find(dining) existing_booking = Booking.find_by_sale_id(sale_id) table.bookings.each do |booking| @@ -51,7 +52,7 @@ class Origami::SalesController < BaseOrigamiController end # Re-compute for add - saleobj.compute(order.source) + saleobj.compute(order.source,tax_type) saleobj.save order.save booking.save diff --git a/app/models/sale.rb b/app/models/sale.rb index e353f523..779e5f91 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -322,7 +322,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute(order_source = nil) + def compute(order_source = nil, tax_type = nil) sales_items = self.sale_items #Computation Fields @@ -341,7 +341,7 @@ class Sale < ApplicationRecord # total_taxable = total_taxable + (item.taxable_price * item.qty) end - apply_tax(total_taxable, order_source) + apply_tax(total_taxable, order_source, tax_type) self.total_amount = subtotal_price self.total_discount = total_discount @@ -434,8 +434,21 @@ class Sale < ApplicationRecord total_tax_amount = 0 tax_incl_exec = "exclusive" #tax_profile - list by order_by - tax_profiles = TaxProfile.all.order("order_by asc") - customer = Customer.find(sale.customer_id) + # tax_profiles = TaxProfile.all.order("order_by asc") + # customer = Customer.find(sale.customer_id) + arr_tax = [] + arr_tax = unique_tax_profiles(order_source, self.customer_id) + + if !arr_tax.empty? + if tax_type.nil? + tax_profiles = TaxProfile.unscoped.where(:id => arr_tax) + else + tax_profiles = TaxProfile.unscoped.where("group_type=?",order_source) + end + else + tax_profiles = TaxProfile.unscoped.where("group_type=?",order_source) + end + # #Creat new tax records if order_source.to_s == "emenu" order_source = "cashier" @@ -505,7 +518,7 @@ class Sale < ApplicationRecord end # Tax Calculate - def apply_tax(total_taxable, order_source = nil) + def apply_tax(total_taxable, order_source = nil, tax_type = nil) shop = Shop.first #if tax is not apply create new record @@ -522,29 +535,32 @@ class Sale < ApplicationRecord order_source = "cashier" end - tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id) - customer = Customer.find(self.customer_id).tax_profiles + # tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id) + # customer = Customer.find(self.customer_id).tax_profiles arr_tax = [] - - arr_tax = customer - tax_data + arr_tax = unique_tax_profiles(order_source, self.customer_id) if !arr_tax.empty? - tax_profiles = TaxProfile.unscoped.where("id in ?",arr_tax) + if tax_type.nil? + tax_profiles = TaxProfile.unscoped.where(:id => arr_tax) + else + tax_profiles = TaxProfile.unscoped.where("group_type=?",order_source) + end else tax_profiles = TaxProfile.unscoped.where("group_type=?",order_source) end #Create new tax records tax_profiles.each do |tax| if tax.group_type.to_s == order_source.to_s - # customer.tax_profiles.each do |cus_tax| - # if cus_tax.to_i == tax.id + if tax_type + if tax_type.to_s == tax.name.to_s || tax_type == 'all' sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate # substract , to give after discount - total_tax = total_taxable - self.total_discount + total_tax = total_taxable - total_discount #include or execulive if tax.inclusive tax_incl_exec = "inclusive" @@ -555,16 +571,43 @@ class Sale < ApplicationRecord 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 - # end - # end + end + else + # customer.tax_profiles.each do |cus_tax| + # if cus_tax.to_i == tax.id + sale_tax = SaleTax.new(:sale => self) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate + + # substract , to give after discount + total_tax = total_taxable - self.total_discount + #include or execulive + if tax.inclusive + tax_incl_exec = "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 + # end + # end + end end end self.tax_type = tax_incl_exec @@ -2844,9 +2887,21 @@ def self.get_sale_data_for_other_payment_credit(sale_id) return query end -def difference(other) - h = other.each_with_object(Hash.new(0)) { |e,h| h[e] += 1 } - reject { |e| h[e] > 0 && h[e] -= 1 } +def unique_tax_profiles(order_source, customer_id) + tax_data = TaxProfile.unscoped.where("group_type='#{order_source}'").pluck(:id) + customer_tax_profiles = Customer.find(customer_id).tax_profiles + + arr_data = [] + if !customer_tax_profiles.empty? + customer_tax_profiles.each do |value1| + if tax_data.include? value1.to_i + arr_data.push(value1.to_i) + end + end + return arr_data + else + return tax_data + end end private diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index eed3d8ce..aef82ecf 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -370,7 +370,7 @@ <% else %> No Tax <% end %>
- <%if !@webview %> + <%if !@webview && @changable_tax %> <% end %> @@ -1103,10 +1103,11 @@ var dining_id = "<%= @dining.id %>"; var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %> var ajax_url = "/origami/sale/append_order"; + var tax_type = localStorage.getItem("tax_type"); $.ajax({ type: "POST", url: ajax_url, - data: 'dining_id=' + dining_id + "&sale_id=" + sale_id, + data: 'dining_id=' + dining_id + "&sale_id=" + sale_id + "&tax_type=" + tax_type, success: function (result) { swal({ title: "Information!", diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 195719bd..245467f9 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -118,7 +118,7 @@ <% else %> No Tax <% end %>
- <%if @sale_payment.nil? %> + <%if @sale_payment.nil? && @changable_tax %> <% end %> diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 155e1e07..59546349 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -404,7 +404,7 @@ <% else %> No Tax <% end %>
- <%if !@webview %> + <%if !@webview && @changable_tax %> <% end %> @@ -1167,10 +1167,11 @@ $('#add_invoice').on('click',function(){ var dining_id = "<%= @room.id %>" var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %> var ajax_url = "/origami/sale/append_order"; + var tax_type = localStorage.getItem("tax_type"); $.ajax({ type: "POST", url: ajax_url, - data: 'dining_id='+ dining_id + "&sale_id=" + sale_id, + data: 'dining_id='+ dining_id + "&sale_id=" + sale_id + "&tax_type=" + tax_type, success:function(result){ swal({ title: "Information!", From a5efbe9af7c5de8e3a613d837473e06e337b9aba Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 2 Aug 2018 18:00:22 +0630 Subject: [PATCH 07/15] change query for credit with order source --- app/models/sale_payment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 3e0ad377..36f88638 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -866,9 +866,9 @@ class SalePayment < ApplicationRecord .joins("INNER JOIN orders o ON o.order_id = so.order_id") if params[:type] == "cashier" - query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) and s.sale_status = 'completed' AND o.source='#{params[:type]}' OR o.source='emenu' #{receipt_no} #{customer}") + query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND o.source='#{params[:type]}' OR o.source='emenu' END) and s.sale_status = 'completed' #{receipt_no} #{customer}") else - query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) and s.sale_status = 'completed' AND o.source='#{params[:type]}' #{receipt_no} #{customer}") + query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND o.source='#{params[:type]}' END) and s.sale_status = 'completed' #{receipt_no} #{customer}") end query = query.group("s.receipt_no") .order("s.receipt_date ASC, s.receipt_no ASC") From b1d0bf8daa5a9c056481fd567da771e65cfceb68 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 3 Aug 2018 09:48:35 +0630 Subject: [PATCH 08/15] check shift --- app/models/sale.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 779e5f91..1f2d591a 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -82,7 +82,7 @@ class Sale < ApplicationRecord self.tax_type = "exclusive" # set cashier - if order_source = "emenu" + if order_source.downcase == "emenu" table = DiningFacility.find(booking.dining_facility_id) cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first From 27271c429e798ecdddae09159ce93c8ae3c50fe8 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 3 Aug 2018 15:46:59 +0630 Subject: [PATCH 09/15] change format --- app/models/order_reservation.rb | 2 +- .../reports/order_reservation/index.html.erb | 26 +++++++++---------- .../reports/order_reservation/index.xls.erb | 12 ++++----- .../order_reservations/index.html.erb | 18 +++++++------ .../order_reservations/show.html.erb | 11 +++++++- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 5fdc9643..9fbc7e4d 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -70,7 +70,7 @@ class OrderReservation < ApplicationRecord order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount] order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge] order_reservation.grand_total = order_reserve[:payment_info][:grand_total] - order_reservation.transaction_fee = order_reserve[:order_info][:transaction_fee] + order_reservation.transaction_fee = order_reserve[:payment_info][:transaction_fee] order_reservation.order_remark = order_reserve[:order_info][:order_remark] end if order_reserve[:reservation_info] diff --git a/app/views/reports/order_reservation/index.html.erb b/app/views/reports/order_reservation/index.html.erb index 439e7772..0ccaef5b 100755 --- a/app/views/reports/order_reservation/index.html.erb +++ b/app/views/reports/order_reservation/index.html.erb @@ -52,9 +52,9 @@ <%= t("views.right_panel.detail.discount_amount") %> <%= t("views.right_panel.detail.delivery_fee") %> <%= t("views.right_panel.detail.convenience_charge") %> - <%= t("views.right_panel.detail.delivery_tax") %> + <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> <%= t("views.right_panel.detail.grand_total") %> <%= t("views.right_panel.detail.transaction_fee") %> @@ -89,7 +89,7 @@ total_tax = 0.0 total_amount = 0.0 grand_total = 0.0 - transaction_fee = 0.0 + total_transaction_fee = 0.0 %> <% unless @order_reservation_data.blank? %> <% @order_reservation_data.each do |order_reservation| %> @@ -118,11 +118,9 @@ total_tax += order_reservation.total_tax.to_f total_amount += order_reservation.total_amount.to_f grand_total += order_reservation.grand_total.to_f - %> - <% if order_reservation.transaction_fee && order_reservation.transaction_fee > 0 - transaction_fee += order_reservation.transaction_fee.to_f - end %> - <% + + total_transaction_fee += order_reservation.transaction_fee.to_f + if order_reservation.provider == 'pick_up' provider = "Pick-Up" elsif order_reservation.provider == 'direct_delivery' @@ -149,9 +147,9 @@ <%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_with_precision(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> <%= number_with_precision(order_reservation.transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> @@ -165,12 +163,12 @@ <%= number_with_precision(total_discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(total_delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(total_convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(total_delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + + <%= number_with_precision(total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_with_precision(total_transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> diff --git a/app/views/reports/order_reservation/index.xls.erb b/app/views/reports/order_reservation/index.xls.erb index bb444043..08f2c5e9 100755 --- a/app/views/reports/order_reservation/index.xls.erb +++ b/app/views/reports/order_reservation/index.xls.erb @@ -35,9 +35,9 @@ <%= t("views.right_panel.detail.discount_amount") %> <%= t("views.right_panel.detail.delivery_fee") %> <%= t("views.right_panel.detail.convenience_charge") %> - <%= t("views.right_panel.detail.delivery_tax") %> + <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> <%= t("views.right_panel.detail.grand_total") %> <%= t("views.right_panel.detail.transaction_fee") %> @@ -123,9 +123,9 @@ <%= discount_amount rescue '0.0'%> <%= delivery_fee rescue '0.0'%> <%= convenience_charge rescue '0.0'%> - <%= delivery_tax rescue '0.0'%> + <%= order_reservation.total_tax rescue '0.0'%> <%= order_reservation.grand_total rescue '0.0' %> <%= order_reservation.transaction_fee rescue '0.0' %> @@ -139,9 +139,9 @@ <%= total_discount_amount rescue '0.0'%> <%= total_delivery_fee rescue '0.0'%> <%= total_convenience_charge rescue '0.0'%> - <%= total_delivery_tax rescue '0.0'%> + <%= total_tax rescue '0.0'%> <%= grand_total rescue '0.0'%> <%= transaction_fee rescue '0.0'%> diff --git a/app/views/transactions/order_reservations/index.html.erb b/app/views/transactions/order_reservations/index.html.erb index f8063fd2..3766f092 100644 --- a/app/views/transactions/order_reservations/index.html.erb +++ b/app/views/transactions/order_reservations/index.html.erb @@ -11,10 +11,10 @@
- +
- @@ -187,6 +189,13 @@ <% end %> + <% if total_transaction_fee > 0 %> + + + + + + <% end %>
+ <%= form_tag transactions_order_reservations_path, :method => :get do %>
@@ -65,7 +65,7 @@
- +
@@ -81,11 +81,12 @@ - + + @@ -152,16 +153,17 @@ - + + <% end %> <% else %> - + <% end %>
<%= t("views.right_panel.detail.discount_amount") %> <%= t("views.right_panel.detail.delivery_fee") %> <%= t("views.right_panel.detail.convenience_charge") %><%= t("views.right_panel.detail.delivery_tax") %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> <%= t("views.right_panel.detail.grand_total") %><%= t("views.right_panel.detail.transaction_fee") %>
<%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%><%= number_with_precision(delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> <%= number_with_precision(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %><%= number_with_precision(order_reservation.transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %>

There is no data for search....

There is no data for search....

diff --git a/app/views/transactions/order_reservations/show.html.erb b/app/views/transactions/order_reservations/show.html.erb index 7ab06b0c..a0c59af5 100755 --- a/app/views/transactions/order_reservations/show.html.erb +++ b/app/views/transactions/order_reservations/show.html.erb @@ -99,12 +99,13 @@ total_tax = 0.0 total_amount = 0.0 grand_total = 0.0 + total_transaction_fee = 0.0 %> <% discount_amount = @order_reservation.discount_amount delivery_fee = @order_reservation.delivery_fee ? @order_reservation.delivery_fee : 0.0 convenience_charge = @order_reservation.convenience_charge - if !JSON.parse(order_reservation.taxes).empty? + if !JSON.parse(@order_reservation.taxes).empty? JSON.parse(@order_reservation.taxes).each do |tax_data| if tax_data[0] == "delivery_tax" delivery_tax = tax_data[1] @@ -124,6 +125,7 @@ total_tax += @order_reservation.total_tax.to_f total_amount += @order_reservation.total_amount.to_f grand_total += @order_reservation.grand_total.to_f + total_transaction_fee += @order_reservation.transaction_fee.to_f %>
<%= number_with_precision(grand_total, precision:precision.to_i, delimiter:delimiter) rescue ' '%>
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.transaction_fee") %><%= number_with_precision(total_transaction_fee, precision:precision.to_i, delimiter:delimiter) rescue ' '%>
From 963172eec06627a7ca729d812817385d52273bb3 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 3 Aug 2018 16:36:58 +0630 Subject: [PATCH 10/15] remove null false for product_alt_name in slae_items migration --- db/migrate/20170403161857_create_sale_items.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20170403161857_create_sale_items.rb b/db/migrate/20170403161857_create_sale_items.rb index 14882cbc..66a32f14 100755 --- a/db/migrate/20170403161857_create_sale_items.rb +++ b/db/migrate/20170403161857_create_sale_items.rb @@ -6,7 +6,7 @@ class CreateSaleItems < ActiveRecord::Migration[5.1] t.string :product_code, :null => false t.string :item_instance_code t.string :product_name, :null => false - t.string :product_alt_name, :null => false + t.string :product_alt_name t.integer :account_id, :index => true, :limit => 8, :null => false, :default => 1 t.string :status, :index => true t.string :remark, :index => true From 6e13aa73a33e5c62592925ed9677bae52bb76855 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 6 Aug 2018 10:56:33 +0630 Subject: [PATCH 11/15] update for bill api with order source --- app/controllers/api/bill_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index d5eb77b1..0d16414c 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -14,10 +14,13 @@ class Api::BillController < Api::ApiController # for Multiple Cashier by Zone table = DiningFacility.find(booking.dining_facility_id) + bk_order = BookingOrder.find_by_booking_id(booking.booking_id) + order = Order.find(bk_order.order_id) + if booking if booking.sale_id.nil? @sale = Sale.new - @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, current_login_employee, "cashier") + @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, current_login_employee, order.source) @sale_data = Sale.find_by_sale_id(@sale_id) else @status = true @@ -41,8 +44,9 @@ class Api::BillController < Api::ApiController end elsif (params[:order_id]) + order = Order.find(params[:order_id]) @sale = Sale.new - @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier, "cashier") + @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier, order.source) # for Job booking = Booking.find_by_sale_id(@sale_id) From f0f19edcd65bc492e9e4c77a02074527825a21e6 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 6 Aug 2018 12:52:47 +0630 Subject: [PATCH 12/15] update bill request for employee --- app/controllers/api/bill_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 0d16414c..18a3d269 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -16,11 +16,15 @@ class Api::BillController < Api::ApiController bk_order = BookingOrder.find_by_booking_id(booking.booking_id) order = Order.find(bk_order.order_id) - + + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first + cashier = Employee.find(shift.employee_id) + if booking if booking.sale_id.nil? @sale = Sale.new - @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, current_login_employee, order.source) + @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, cashier, order.source) @sale_data = Sale.find_by_sale_id(@sale_id) else @status = true From b933f959f60eb30c776a93b75539cb410b6ecac6 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 6 Aug 2018 17:46:27 +0630 Subject: [PATCH 13/15] update bill for multiple zone --- app/controllers/api/bill_controller.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 18a3d269..b71d3460 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -18,8 +18,26 @@ class Api::BillController < Api::ApiController order = Order.find(bk_order.order_id) cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + puts cashier_zone.to_json + puts "cashier_zone" shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first - cashier = Employee.find(shift.employee_id) + if !shift.nil? + cashier = Employee.find(shift.employee_id) + else + multiple_zone = CashierTerminalByZone.where('zone_id = #{cashier_zone.zone_id}') + puts cashier_zone.to_json + puts "cashier_zone" + multiple_zone.each do |zone| + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first + puts shift.to_json + puts "shift" + if !shift.nil? then + cashier = Employee.find(shift.employee_id) + break + end + + end + end if booking if booking.sale_id.nil? From 81a387e5224cd8bed49f232c331f5f7674550699 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 7 Aug 2018 09:33:26 +0630 Subject: [PATCH 14/15] update multiple zone with terminal --- app/controllers/api/bill_controller.rb | 18 +++++++----------- app/models/sale.rb | 11 +++++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index b71d3460..9ad9c5ee 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -18,24 +18,20 @@ class Api::BillController < Api::ApiController order = Order.find(bk_order.order_id) cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - puts cashier_zone.to_json - puts "cashier_zone" + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first + + #for multiple zone with terminal if !shift.nil? cashier = Employee.find(shift.employee_id) else - multiple_zone = CashierTerminalByZone.where('zone_id = #{cashier_zone.zone_id}') - puts cashier_zone.to_json - puts "cashier_zone" + multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}") multiple_zone.each do |zone| shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first - puts shift.to_json - puts "shift" - if !shift.nil? then - cashier = Employee.find(shift.employee_id) + if !shift.nil? then + cashier = Employee.find(shift.employee_id) break - end - + end end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 1f2d591a..31b16253 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -86,6 +86,17 @@ class Sale < ApplicationRecord table = DiningFacility.find(booking.dining_facility_id) cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first + #for multiple zone with terminal + if shift.nil? + multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}") + multiple_zone.each do |zone| + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first + if !shift.nil? then + break + end + end + end + else open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") current_shift = ShiftSale.current_shift From 456bb61f6187c86b8a3c923b0dd831f1af1ced5f Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 7 Aug 2018 10:43:40 +0630 Subject: [PATCH 15/15] add fun: --- .../api/sound_effect_controller.rb | 2 +- app/controllers/application_controller.rb | 32 ++++++++++++++++++- app/views/layouts/_left_sidebar.html.erb | 12 ++++--- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/sound_effect_controller.rb b/app/controllers/api/sound_effect_controller.rb index e53e69b9..97dc3db5 100644 --- a/app/controllers/api/sound_effect_controller.rb +++ b/app/controllers/api/sound_effect_controller.rb @@ -22,7 +22,7 @@ class Api::SoundEffectController < Api::ApiController end ActionCable.server.broadcast "sound_effect_channel",data: {status: params[:status], message: params[:message]},shop_code: shop_code,from:from,audio:audio else - render :json => { :status => true, :message => "Something wrongs!" } + render :json => { :status => false, :message => "Something wrongs!" } end end #sound effect / alarm api for doemal side calling diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 330c5c1f..4ad0c42a 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base #before_action :check_installation protect_from_forgery with: :exception - helper_method :shop_detail + helper_method :shop_detail, :order_reservation, :bank_integration # lookup domain for db from provision # before_action :set_locale # helper_method :current_company,:current_login_employee,:current_user @@ -21,6 +21,36 @@ class ApplicationController < ActionController::Base def shop_detail @shop = Shop.first end + + def order_reservation + order_reserve = Lookup.collection_of('order_reservation') + status = false + if !order_reserve.empty? + order_reserve.each do |order| + if order[0] == 'OrderReservation' + if order[1] == '1' + status = true + end + end + end + end + return status + end + + def bank_integration + bank_integration = Lookup.collection_of('bank_integration') + status = false + if !bank_integration.empty? + bank_integration.each do |bank| + if bank[0] == 'Bank Integration' + if bank[1] == '1' + status = true + end + end + end + end + return status + end end diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index a4340f0e..69021cc2 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -119,9 +119,11 @@ <% end %> <% if can? :manage, OrderReservation %> -
  • - <%= t("views.right_panel.detail.order_reservation") %> -
  • + <% if order_reservation %> +
  • + <%= t("views.right_panel.detail.order_reservation") %> +
  • + <% end %> <% end %> @@ -141,9 +143,11 @@
  • Product Sale
  • + <% if order_reservation %>
  • - Order Reservation + <%= t("views.right_panel.detail.order_reservation") %>
  • + <% end %>
  • Receipt