From fd44a57689c301466db315f7512298d6f7e4ec98 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 26 Jul 2018 11:10:54 +0630 Subject: [PATCH] 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