From 578c14ccc33f1b81ed26786975a543a308256fd0 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Fri, 25 May 2018 16:22:30 +0630 Subject: [PATCH] Pull from master --- app/assets/javascripts/addorder.js | 11 +- .../javascripts/settings/processing_items.js | 4 - app/assets/stylesheets/addorder.scss | 19 +- app/assets/stylesheets/origami.scss | 5 + .../order_reservation_controller.rb | 2 +- app/controllers/api/orders_controller.rb | 3 + app/controllers/api/survey_controller.rb | 4 +- .../origami/order_reservation_controller.rb | 12 +- .../origami/payments_controller.rb | 24 +- .../origami/product_commissions_controller.rb | 82 ++--- app/models/ability.rb | 3 + app/models/commission.rb | 2 +- app/models/order.rb | 133 ++++---- app/models/product_commission.rb | 5 +- app/models/sale.rb | 106 +++---- app/pdf/receipt_bill_a5_pdf.rb | 6 +- app/pdf/receipt_bill_pdf.rb | 7 +- .../restaurant/menu/_menu_item.json.jbuilder | 2 +- app/views/origami/addorders/detail.html.erb | 8 +- .../origami/dashboard/_menu.json.jbuilder | 11 +- app/views/origami/payments/show.html.erb | 125 +++++++- .../load_commissioners.html.erb | 12 +- app/views/reports/commission/index.html.erb | 2 +- app/views/reports/dailysale/index.xls.erb | 297 +++++++++--------- config/routes.rb | 2 + lib/tasks/clear_data.rake | 7 +- 26 files changed, 536 insertions(+), 358 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 3be2f34d..3fea4c6b 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -1012,12 +1012,14 @@ $(function() { //calculate subtotal function calculate_sub_total(){ var total_price = 0; + var total_qty = 0; var taxable_amount = 0; var item_row = $('.summary-items tbody tr'); $(item_row).each(function(i){ var unit_price = parseFloat($(item_row[i]).attr('data-price')); var qty = parseFloat($(item_row[i]).children('#item_qty').text()); + total_qty += qty; total_price += qty*unit_price; }); var fixed_total_price = parseFloat(total_price).toFixed(2); @@ -1026,6 +1028,9 @@ $(function() { $('#sub_total').empty(); $('#sub_total').append(fixed_total_price); + $('#total_qty').empty(); + $('#total_qty').append(total_qty); + if (item_row.length > 0) { $('.create').removeAttr("disabled", false); }else{ @@ -1432,7 +1437,8 @@ $(function() { } } - row = '
' + row = '
' + +'
' +'
' +'
'+ menu_items[field].name +'
' +"
' +''+ price +'' +'
' - +'
'; + +'
' + +'
'; ; $('.menu_items_list').append(row); } //end instances in menu-items alest 1 instance diff --git a/app/assets/javascripts/settings/processing_items.js b/app/assets/javascripts/settings/processing_items.js index 1dc5e97f..e43aedde 100755 --- a/app/assets/javascripts/settings/processing_items.js +++ b/app/assets/javascripts/settings/processing_items.js @@ -1,7 +1,6 @@ $(document).ready(function() { $(".processitems").click(function(event){ event.preventDefault(); - console.log($(this).data("id")); var item = $(this).data("id"); $(this).toggleClass("opi_selected"); @@ -13,7 +12,6 @@ $(document).ready(function() { console.log($(this).data("id")); var group_id = $(this).data("id"); var selector = "#" + group_id + " li div"; - console.log ($(selector)); $(selector).removeClass("opi_selected"); $(selector).addClass("opi_selected"); @@ -25,7 +23,6 @@ $(document).ready(function() { console.log($(this).data("id")); var group_id = $(this).data("id"); var selector = "#" + group_id + " li div"; - console.log ($(selector)); $(selector).removeClass("opi_selected"); }); @@ -36,7 +33,6 @@ $(document).ready(function() { var items = new Array(); selected_div = $(".opi_selected"); $.each( selected_div, function( key, value ) { - console.log($(value).attr("data-id")); items.push($(value).attr("data-id")); }); diff --git a/app/assets/stylesheets/addorder.scss b/app/assets/stylesheets/addorder.scss index 929ffb13..36ea4e33 100755 --- a/app/assets/stylesheets/addorder.scss +++ b/app/assets/stylesheets/addorder.scss @@ -12,6 +12,7 @@ section .content{ } .custom-card { border: 2px solid rgba(0, 0, 0, 0.125) !important; + margin-bottom: 7px !important; } .custom-card-footer{ padding:0.35rem 1.25rem !important; @@ -72,16 +73,26 @@ section .content{ .nav-tabs { background-color: #ccc; } +.nav-tabs li a.active{ + border-bottom:1px solid #54A5AF !important; +} .nav-tabs .nav-link { padding: 0.7286rem 0.2575; border-top-left-radius: 0rem; border-top-right-radius: 0rem; } + +.nav-tabs .nav-link:focus, .nav-tabs .nav-link:hover { + color: #54A5AF #54A5AF #54A5AF; +} +.nav-tabs .nav-link.active:focus, .nav-tabs .nav-link.active:hover { + background-color: #009688; +} .nav-tabs .nav-link.active, .nav-tabs .nav-item.show .nav-link { - background-color: #a1aade; - border-left: 6px solid #111; - color:#54A5AF; - font-weight: bold; + background-color: #fff !important; + border-left: 6px solid #54A5AF !important; + color: #54A5AF !important; + font-weight: bold !important; border-color: #fff #fff #fff #54A5AF; } .sub_category_list{ diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 855ee984..7ce4e1ed 100755 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -462,4 +462,9 @@ iframe { /* section class for webview */ .section-margin { margin-top: -50px; +} + +.tax-btn-box { + width: 230px; + height: 80px; } \ No newline at end of file diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 32e87a20..97c44df9 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -63,7 +63,7 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController order_reservation = params order_reservation_id, flag = OrderReservation.addOrderReservationInfo(order_reservation) - if flag #&& ENV["SERVER_MODE"] != 'cloud' + if flag shop = Shop.find_by_id(1) if !shop.shop_code.nil? shop_code = shop.shop_code diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 187d1139..0c3703fe 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -117,6 +117,9 @@ class Api::OrdersController < Api::ApiController end @status, @booking = @order.generate + if @status && @booking + Order.process_order_queue(@order.order_id,@order.table_id,@order.source) + end # # for parallel order # remoteIP = "" # begin diff --git a/app/controllers/api/survey_controller.rb b/app/controllers/api/survey_controller.rb index 27fe327d..06c9f643 100644 --- a/app/controllers/api/survey_controller.rb +++ b/app/controllers/api/survey_controller.rb @@ -18,8 +18,8 @@ class Api::SurveyController < Api::ApiController cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id) shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) - if params[:id] - survey = Survey.find(params[:id]) + if params[:survey][:id] + survey = Survey.find(params[:survey][:id]) else survey = Survey.new end diff --git a/app/controllers/origami/order_reservation_controller.rb b/app/controllers/origami/order_reservation_controller.rb index a3421fbd..ea760e33 100644 --- a/app/controllers/origami/order_reservation_controller.rb +++ b/app/controllers/origami/order_reservation_controller.rb @@ -48,8 +48,16 @@ class Origami::OrderReservationController < BaseOrigamiController end def send_status - response = OrderReservation.send_status_to_ordering(params[:url],params[:ref_no],params[:status],params[:waiting_time],params[:min_type],params[:reason]) - + order_reservation = OrderReservation.find_by_transaction_ref(params[:ref_no]) + if !order_reservation.nil? + if !ShiftSale.current_shift.nil? || params[:status] == 'accepted' || (order_reservation.status == 'new' && params[:status] == 'rejected') + response = OrderReservation.send_status_to_ordering(params[:url],params[:ref_no],params[:status],params[:waiting_time],params[:min_type],params[:reason]) + else + response = { status: false, message: 'No current shift open for this employee!'} + end + else + response = { status: false, message: 'There is no order for '+params[:ref_no]+'!'} + end render :json => response end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 045afafb..313cc10c 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -96,6 +96,8 @@ class Origami::PaymentsController < BaseOrigamiController cash = params[:cash] sale_id = params[:sale_id] member_info = nil + type = params[:type] + tax_type = params[:tax_type] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) @@ -298,11 +300,18 @@ class Origami::PaymentsController < BaseOrigamiController # accounts = @customer.tax_profiles accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") @account_arr =[] + @tax_arr =[] accounts.each do |acc| account = TaxProfile.find(acc.id) - @account_arr.push(account) + # @account_arr.push(account) + @tax_arr.push(account.name) + end + sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id) + if !sale_taxes.empty? + sale_taxes.each do |sale_tax| + @account_arr.push(sale_tax) + end end - rebate = MembershipSetting.find_by_rebate(1) # get member information if @customer.membership_id != nil && rebate @@ -571,4 +580,15 @@ class Origami::PaymentsController < BaseOrigamiController render :json => result.to_json # render :json => {status: true} end + + #changable tax for sale + def change_tax + sale_id = params[:sale_id] + order_source = params[:cashier_type] + tax_type = params[:tax_type] + sale = Sale.find(sale_id) + sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount,nil,order_source,tax_type) + + render json: JSON.generate({:status => true}) + end end \ No newline at end of file diff --git a/app/controllers/origami/product_commissions_controller.rb b/app/controllers/origami/product_commissions_controller.rb index 1156827a..a9c74b70 100755 --- a/app/controllers/origami/product_commissions_controller.rb +++ b/app/controllers/origami/product_commissions_controller.rb @@ -83,54 +83,66 @@ class Origami::ProductCommissionsController < BaseOrigamiController def set_commissioner_to_sale_item # byebug - deselect = false - sale_item_id = params[:sale_item_id] + deselect = false + type = nil + sale_item_id = params[:sale_item_id] commissioner_id = params[:commissioner_id] - @sale_item = SaleItem.find(sale_item_id) - @menu_item = MenuItem.find_by_item_code(@sale_item.product_code) + @sale_item = SaleItem.find(sale_item_id) + @menu_item = MenuItem.find_by_item_code(@sale_item.product_code) # @commission = Commission.where('product_code = ? AND is_active = ?', @menu_item.item_code, true).take - Commission.all.each do |com| - if com.product_code.include? @menu_item.item_code && com.is_active == true - @commission = Commission.find(com.id) - break + Commission.all.active.each do |com| + if com.product_code != "[]" + if com.product_code.to_s.include? @menu_item.item_code + @commission = Commission.find(com.id) + break + end end end - @commissioner = Commissioner.where('id = ? AND is_active = ?', commissioner_id, true).take + @commissioner = Commissioner.where('id = ? AND is_active = ?', commissioner_id, true).take @product_commission = ProductCommission.where('sale_item_id = ?', @sale_item.id).take + if !@commission.nil? && @commissioner.commission_id == @commission.commission_id if !@product_commission.nil? - if @product_commission.commissioner_id == @commissioner.id - @product_commission.destroy - deselect = true - else - @product_commission.commissioner_id = @commissioner.id - deselect = false - end - else - @product_commission = ProductCommission.new - @product_commission.product_code = @menu_item.item_code - @product_commission.product_type = 'menu_item' # use for dummy data ToDo::need to change product type - unless @commission.nil? - @product_commission.commission_id = @commission.id - if @commission.commission_type == 'Percentage' - @product_commission.price = @sale_item.unit_price * (@commission.amount / 100.0) - @product_commission.amount = @product_commission.price * @sale_item.qty - elsif @commission.commission_type == 'Net Amount' - @product_commission.price = @commission.amount - @product_commission.amount = @product_commission.price * @sale_item.qty + if @product_commission.commissioner_id == @commissioner.id + @product_commission.destroy + deselect = true + type = "remove" + # render json: {status: true,deselect:deselect, message: "Remove Success !"} + else + @product_commission.commissioner_id = @commissioner.id + deselect = false end - end - @product_commission.commissioner_id = @commissioner.id - @product_commission.qty = @sale_item.qty - @product_commission.sale_id = @sale_item.sale_id - @product_commission.sale_item_id = @sale_item.sale_item_id + else + @product_commission = ProductCommission.new + @product_commission.product_code = @menu_item.item_code + @product_commission.product_type = 'menu_item' # use for dummy data ToDo::need to change product type + unless @commission.nil? + @product_commission.commission_id = @commission.id + if @commission.commission_type == 'Percentage' + @product_commission.price = @sale_item.unit_price * (@commission.amount / 100.0) + @product_commission.amount = @product_commission.price * @sale_item.qty + elsif @commission.commission_type == 'Net Amount' + @product_commission.price = @commission.amount + @product_commission.amount = @product_commission.price * @sale_item.qty + end + end + @product_commission.commissioner_id = @commissioner.id + @product_commission.qty = @sale_item.qty + @product_commission.sale_id = @sale_item.sale_id + @product_commission.sale_item_id = @sale_item.sale_item_id end if @product_commission.save - render json: {status: true, deselect: deselect} + message = "Success !" + if type == "remove" + message = "Remove Success !" + end + render json: {status: true, deselect:deselect,type:type,message: message} else - render json: {status: false, deselect: deselect} + render json: {status: false, deselect:deselect,type:type,message: "No Commission"} end + else + render json: {status: false, deselect:deselect,type:type,message: "No Commission"} end end diff --git a/app/models/ability.rb b/app/models/ability.rb index fbf66f57..9f1f105b 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -71,6 +71,7 @@ class Ability can :rounding_adj, :payment can :foc, :payment can :print, :payment + can :change_tax, :payment can :move_dining, :movetable can :moving, :movetable @@ -154,6 +155,7 @@ class Ability can :rounding_adj, :payment can :foc, :payment can :print, :payment + can :change_tax, :payment can :move_dining, :movetable can :moving, :movetable @@ -249,6 +251,7 @@ class Ability can :rounding_adj, :payment can :print, :payment can :foc, :payment + can :change_tax, :payment can :manage, Commission can :manage, Commissioner diff --git a/app/models/commission.rb b/app/models/commission.rb index e331eb59..32aa8a04 100755 --- a/app/models/commission.rb +++ b/app/models/commission.rb @@ -10,7 +10,7 @@ class Commission < ApplicationRecord # validations validates_presence_of :name, :commission_type, :amount - + scope :active, -> {where(is_active: true)} private def generate_custom_id self.commission_id = SeedGenerator.generate_id(self.class.name, 'COM') diff --git a/app/models/order.rb b/app/models/order.rb index 9a52942e..5edc778a 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -301,13 +301,6 @@ class Order < ApplicationRecord end # end end - - def check_cup_status(status) - if status.include? "Active: active (running)" || "Active: active (exited)" #"Cup Server is already running" - return true - end - return false - end #send order items and send to order queue def send_order_broadcast(booking) @@ -317,10 +310,10 @@ class Order < ApplicationRecord #Send to background job for processing # OrderBroadcastJob.perform_later(table,type) if ENV["SERVER_MODE"] == 'cloud' - from = request.subdomain + "." + request.domain - else - from = "" - end + from = request.subdomain + "." + request.domain + else + from = "" + end ActionCable.server.broadcast "order_channel",table: table,type:type,from:from end @@ -485,68 +478,74 @@ class Order < ApplicationRecord end #Process order items and send to order queue - # def process_order_queue - # print_status = nil - # cup_status = nil + def self.process_order_queue(order_id,table_id,source) + print_status = nil + cup_status = nil - # #Send to background job for processing - # order = Order.find(self.id) - # sidekiq = Lookup.find_by_lookup_type("sidekiq") + #Send to background job for processing + order = Order.find(order_id) + sidekiq = Lookup.find_by_lookup_type("sidekiq") - # if ENV["SERVER_MODE"] != 'cloud' - # cup_status = `#{"sudo service cups status"}` - # print_status = check_cup_status(cup_status) - # end + if ENV["SERVER_MODE"] != 'cloud' + cup_status = `#{"sudo service cups status"}` + print_status = check_cup_status(cup_status) + end - # if print_status - # if !sidekiq.nil? - # OrderQueueProcessorJob.perform_later(self.id, self.table_id) - # else - # if order - # oqs = OrderQueueStation.new - # oqs.process_order(order, self.table_id, self.source) - # end - # # assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) - # # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order - # end - # else - # if ENV["SERVER_MODE"] != 'cloud' - # cup_start = `#{"sudo service cups start"}` - # cup_status = `#{"sudo service cups status"}` - # print_status = check_cup_status(cup_status) - # end + if print_status + if !sidekiq.nil? + OrderQueueProcessorJob.perform_later(order_id, table_id) + else + if order + oqs = OrderQueueStation.new + oqs.process_order(order, table_id, source) + end + # assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) + # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + end + else + if ENV["SERVER_MODE"] != 'cloud' + cup_start = `#{"sudo service cups start"}` + cup_status = `#{"sudo service cups status"}` + print_status = check_cup_status(cup_status) + end - # if print_status - # if !sidekiq.nil? - # OrderQueueProcessorJob.perform_later(self.id, self.table_id) - # else - # if order - # oqs = OrderQueueStation.new - # oqs.process_order(order, self.table_id, self.source) - # end - # # assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) - # # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order - # end - # else - # if ENV["SERVER_MODE"] != 'cloud' + if print_status + if !sidekiq.nil? + OrderQueueProcessorJob.perform_later(order_id, table_id) + else + if order + oqs = OrderQueueStation.new + oqs.process_order(order, table_id, source) + end + # assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) + # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + end + else + if ENV["SERVER_MODE"] != 'cloud' - # msg = ' Print Error ! Please contact to service' - # ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error' - # end - # if !sidekiq.nil? - # OrderQueueProcessorJob.perform_later(self.id, self.table_id) - # else - # if order - # oqs = OrderQueueStation.new - # oqs.process_order(order, self.table_id, self.source) - # end - # assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) - # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order - # end - # end - # end - # end + msg = ' Print Error ! Please contact to service' + ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error' + end + if !sidekiq.nil? + OrderQueueProcessorJob.perform_later(order_id, table_id) + else + if order + oqs = OrderQueueStation.new + oqs.process_order(order, table_id, source) + end + assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) + ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + end + end + end + end + def self.check_cup_status(status) + if status.include? "Active: active (running)" || "Active: active (exited)" #"Cup Server is already running" + return true + end + return false + end private diff --git a/app/models/product_commission.rb b/app/models/product_commission.rb index c865c674..9f91673a 100755 --- a/app/models/product_commission.rb +++ b/app/models/product_commission.rb @@ -61,9 +61,10 @@ class ProductCommission < ApplicationRecord end def self.get_transaction(from, to, commissioner) - transaction = all + transaction = ProductCommission.select("product_commissions.*,menu_items.name as porduct_name") + .joins("join menu_items on menu_items.item_code = product_commissions.product_code") if !from.nil? && !to.nil? - transaction = transaction.where('updated_at between ? and ?', from, to) + transaction = transaction.where('product_commissions.updated_at between ? and ?', from, to) end if commissioner != 0 transaction = transaction.where(commissioner_id: commissioner) diff --git a/app/models/sale.rb b/app/models/sale.rb index 24d3f81c..979d265c 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -131,7 +131,6 @@ class Sale < ApplicationRecord if order_source.nil? order_source = order.source end - puts "compute source" compute(order_source) #Update the order items that is billed @@ -346,7 +345,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil) + def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil) sale = Sale.find(sale_id) sales_items = sale_itemss @@ -365,7 +364,7 @@ class Sale < ApplicationRecord end end - compute_tax(sale, total_taxable, total_discount, order_source) + compute_tax(sale, total_taxable, total_discount, order_source, tax_type) sale.total_amount = subtotal_price sale.total_discount = total_discount @@ -412,7 +411,7 @@ class Sale < ApplicationRecord end # Tax Re-Calculte - def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil) + def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil, tax_type=nil) shop = Shop.first(); #if tax is not apply create new record @@ -422,6 +421,7 @@ class Sale < ApplicationRecord end 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) @@ -429,11 +429,9 @@ class Sale < ApplicationRecord if sale.payment_status != 'foc' tax_profiles.each do |tax| - # customer.tax_profiles.each do |cus_tax| - # if cus_tax.to_i == tax.id if tax.group_type.to_s == order_source.to_s - if customer.customer_type.downcase == 'takeaway' - if tax.name.downcase == 'commercial tax' + if tax_type + if tax_type.to_s == tax.name.to_s || tax_type == 'all' sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -442,6 +440,7 @@ class Sale < ApplicationRecord total_tax = total_taxable - 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 @@ -453,39 +452,41 @@ class Sale < ApplicationRecord if shop.calc_tax_order total_taxable = total_taxable + sale_tax.tax_payable_amount end - sale_tax.inclusive = tax.inclusive sale_tax.save end else - sale_tax = SaleTax.new(:sale => sale) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate + # customer.tax_profiles.each do |cus_tax| + # if cus_tax.to_i == tax.id + sale_tax = SaleTax.new(:sale => sale) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate - # substract , to give after discount - total_tax = total_taxable - total_discount - #include or execulive - if tax.inclusive - rate = tax.rate - divided_value = (100 + rate)/rate - sale_tax.tax_payable_amount = total_tax / divided_value - else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 - total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount - end - #new taxable amount is standard rule for step by step - if shop.calc_tax_order - total_taxable = total_taxable + sale_tax.tax_payable_amount - end - sale_tax.inclusive = tax.inclusive - sale_tax.save + # substract , to give after discount + total_tax = total_taxable - 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 - # end end end - + sale.tax_type = tax_incl_exec sale.total_tax = total_tax_amount end @@ -500,6 +501,7 @@ class Sale < ApplicationRecord end total_tax_amount = 0 + tax_incl_exec = "exclusive" #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") @@ -510,11 +512,9 @@ class Sale < ApplicationRecord #Create new tax records tax_profiles.each do |tax| - # customer.tax_profiles.each do |cus_tax| - # if cus_tax.to_i == tax.id if tax.group_type.to_s == order_source.to_s - if customer.customer_type.downcase == 'takeaway' - if tax.name.downcase == 'commercial tax' + # 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 @@ -523,6 +523,7 @@ class Sale < ApplicationRecord 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 @@ -538,37 +539,12 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save - end - else - 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 - 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 - # end end - 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) diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 55b09668..707ecf00 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -303,12 +303,16 @@ class ReceiptBillA5Pdf < Prawn::Document end if sale_data.sale_taxes.length > 0 + incl_tax = "" + if sale_data.tax_type == "inclusive" + incl_tax = "Incl." + end sale_data.sale_taxes.each do |st| move_down line_move y_position = cursor bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do - text "#{ st.tax_name } ( #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 5f3cdc09..92ce858d 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -290,12 +290,17 @@ class ReceiptBillPdf < Prawn::Document end if sale_data.sale_taxes.length > 0 + incl_tax = "" + if sale_data.tax_type == "inclusive" + incl_tax = "Incl." + end + sale_data.sale_taxes.each do |st| move_down line_move y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ st.tax_name } ( #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right diff --git a/app/views/api/restaurant/menu/_menu_item.json.jbuilder b/app/views/api/restaurant/menu/_menu_item.json.jbuilder index 56a8cb5f..d31389e1 100755 --- a/app/views/api/restaurant/menu/_menu_item.json.jbuilder +++ b/app/views/api/restaurant/menu/_menu_item.json.jbuilder @@ -53,7 +53,7 @@ json.id item.id json.code item.item_code json.name item.name json.alt_name item.alt_name -if !request_url.nil? && request_url != '' +if !request_url.nil? && request_url != '' && !item.image_path.url.nil? json.image request_url + item.image_path.url.to_s else json.image item.image_path.url diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 0ba7f60b..bbd9cb79 100644 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -101,7 +101,7 @@
-