From baa1ce5fbc2dd346d76a6fd4a9a3be073fb94b65 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 30 Jun 2017 13:55:26 +0630 Subject: [PATCH 01/11] fix date function for shift sale --- app/models/shift_sale.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index a897de2b..5d459f09 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -21,7 +21,7 @@ class ShiftSale < ApplicationRecord #find open shift where is open today and is not closed and login by current cashier today_date = DateTime.now.strftime("%Y-%m-%d") puts today_date - shift = ShiftSale.where("TO_CHAR(shift_started_at, 'YYYY-MM-DD')=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}", today_date).take + shift = ShiftSale.where("Date(shift_started_at)=#{today_date} and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take return shift #end From fd0ae922eb1f280d25a812d1cca42b345fdcdd42 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 30 Jun 2017 14:11:29 +0630 Subject: [PATCH 02/11] fixed for auto print --- app/models/order_queue_station.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 7e3352d1..c9da3a9f 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -59,11 +59,11 @@ class OrderQueueStation < ApplicationRecord private #Print order_items in 1 slip def print_slip(oqs, order, order_items) - unique_code="OrderSummaryPdf" + unique_code="OrderSummaryPdf" print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_summary(oqs,order.order_id, order_items, print_status="") + order_queue_printer.print_order_summary(print_settings, oqs,order.order_id, order_items, print_status="") AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai| # update print status for order items @@ -80,7 +80,7 @@ class OrderQueueStation < ApplicationRecord # print when complete click print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) - order_queue_printer.print_order_item(oqs,item.order_id, item.item_code, print_status="" ) + order_queue_printer.print_order_item(print_settings, oqs,item.order_id, item.item_code, print_status="" ) # update print status for completed same order items assigned_order_item.each do |ai| From 43b9bdc168d6c53997d9655ec400a5e76b2aa45f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 30 Jun 2017 14:15:04 +0630 Subject: [PATCH 03/11] update shiftsale --- .../reports/shiftsale_controller.rb | 2 +- app/models/sale.rb | 57 +++++++++++++++ app/views/layouts/_header.html.erb | 2 +- app/views/reports/shiftsale/index.html.erb | 69 ++++++++++--------- 4 files changed, 95 insertions(+), 35 deletions(-) diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb index 5f13857d..6d8df8c6 100644 --- a/app/controllers/reports/shiftsale_controller.rb +++ b/app/controllers/reports/shiftsale_controller.rb @@ -1,4 +1,4 @@ -class Reports::ShiftsaleController < ApplicationController +class Reports::ShiftsaleController < BaseReportController # authorize_resource :class => false def index diff --git a/app/models/sale.rb b/app/models/sale.rb index 9c3aea00..313a6f80 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -448,6 +448,63 @@ def self.get_by_shiftsales(from,to) return ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to) end +# def self.get_by_shiftsales(employee,from,to) +# shift_sales = ShiftSale.select('shift_sales.id, cs.name as cashier_station_name, shift_sales.shift_started_at as opening_date, shift_sales.shift_closeed_at as closing_date') +# .joins(" INNER JOIN cashier_terminals cs ON cs.id = shift_sales.cashier_terminal_id") +# .where("shift_sales.employee_id = ? and (shift_sales.shift_started_at between ? and ? OR shift_sales.shift_closeed_at between ? and ? )", employee, from, to, from, to) +# .order("shift_sales.id DESC") + +# sale_arr = Array.new +# shift_sales.each do |shift| +# all_total= Sale.select("grand_total,sr.payment_method, sr.payment_amount, rounding_adjustment") +# .joins("join employees e on sales.cashier_id = e.id join shift_sales sh on sh.id = sales.shift_sale_id") +# .joins("INNER JOIN (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sr ON sr.sale_id = sales.sale_id") +# .where("sales.shift_sale_id =? and sales.sale_status = 'completed' and sales.total_amount != 0",shift.id) + +# void = Sale.select("SUM(sales.grand_total) AS grand_total") +# .joins("join shift_sales sh on sh.id = sales.shift_sale_id") +# .where('sales.sales_status = "void" and sales.total_amount != 0 and sales.shift_sale_id = ?', shift.id) +# .sum(:grand_total) +# cash = all_total.select('sr.payment_type') +# .where('sr.payment_type = "cash"') +# .sum(:amount) + +# credit = all_total.where('sr.payment_type = "credit"') +# .sum(:amount) + +# accept_credit = all_total.select('ci.amout') +# .joins("INNER JOIN credit_items ci ON ci.sale_id = sales.id") +# .where('sr.payment_type = "credit"') +# .sum(:amout) + + + +# foc = all_total.where('sales.payment_type = "foc" and sales.sales_status = "completed"') +# .sum(:grand_total) + +# card = all_total.select('payment_type') +# .where('sr.payment_type = "card"') +# .sum(:amount).to_f + +# rounding_adj = all_total.sum(:rounding_adjustment) + +# discount = all_total.sum(:discount_amount) +# void = void.nil? ? 0 : void +# cash = cash.nil? ? 0 : cash +# credit = credit.nil? ? 0 : credit +# foc = foc.nil? ? 0 : foc +# card = card.nil? ? 0 : card +# accept_credit = accept_credit.nil? ? 0 : accept_credit +# # all_payments = void.to_d + cash.to_d + credit.to_d + foc.to_d + card.to_d + accept_credit.to_d +# all_payments = cash.to_d + credit.to_d + foc.to_d + card.to_d + accept_credit.to_d +# payments = { void_amount: void, cash_amount: cash, credit_amount: credit,accept_credit_amount: accept_credit, foc_amount: foc, card_amount: card, grand_total: all_payments , cashier_station_name: shift.cashier_station_name, opening_date: shift.opening_date, closing_date: shift.closing_date, rounding_adj: rounding_adj } + +# sale_arr.push(payments) +# end + +# return sale_arr +# end + private def generate_custom_id diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 558d35dd..ca16298c 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -42,7 +42,7 @@
  • <%= link_to "Daily Sale Report", reports_dailysale_index_path, :tabindex =>"-1" %>
  • <%= link_to "Sales Item Report", reports_saleitem_index_path, :tabindex =>"-1" %>
  • <%= link_to "Receipt Report", reports_receipt_no_index_path, :tabindex =>"-1" %>
  • - +
  • <%= link_to "Shift Sale Report", reports_shiftsale_index_path, :tabindex =>"-1" %>
  • diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb index 8582a578..a2732834 100644 --- a/app/views/reports/shiftsale/index.html.erb +++ b/app/views/reports/shiftsale/index.html.erb @@ -35,16 +35,17 @@ Cashier Station + Cashier Name Shift Name - Void Amount + Cash Payment - Credit Charges + Credit Payment - FOC Payment + Card Payment Grand Total + -
    Rounding Adj - Rounding Adj + + Grand Total @@ -58,48 +59,50 @@ <% total = 0%> <% rounding_adj = 0%> <% g_total = 0 %> - - <% @sale_data.each do |result| %> + + <% @sale_data.each do |result|%> - <%= result[:cashier_station_name] rescue '-'%> + <%= result.cashier_terminal.name rescue '-'%> - <%= result[:shift_started_at].strftime("%e %b %I:%M%p") rescue '-' %> - - <%= result[:shift_closed_at].strftime("%e %b %I:%M%p") rescue '-' %> + + <%= result.employee.name rescue '-'%> + + <%= result.shift_started_at.strftime("%e %b %I:%M%p") rescue '-' %> - + <%= result.shift_closed_at.strftime("%e %b %I:%M%p") rescue '-' %> - - <%= sprintf "%.2f",result[:cash_amount].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:credit_amount].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:accept_credit_amount].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:foc_amount].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:card_amount].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:grand_total].to_f.to_d rescue '-'%> - <%= sprintf "%.2f",result[:rounding_adj].to_f.to_d rescue '-'%> - <% grand_total = result[:grand_total].to_f - result[:rounding_adj].to_f %> - <%= sprintf "%.2f",grand_total.to_f.to_d rescue '-'%> + + <%= sprintf "%.2f",result.cash_sales.to_f.to_d rescue '-'%> + <%= sprintf "%.2f",result.credit_sales.to_f.to_d rescue '-'%> + + + <%= sprintf "%.2f",result.other_sales.to_f.to_d rescue '-'%> + <%= sprintf "%.2f",result.grand_total.to_f.to_d rescue '-'%> + + + <% grand_total = result.grand_total.to_f %> + <%= sprintf "%.2f",grand_tota.to_f.to_d rescue '-'%> - <% void += result[:void_amount].to_f %> - <% cash += result[:cash_amount].to_f %> - <% credit += result[:credit_amount].to_f %> - <% accept_credit += result[:accept_credit_amount].to_f %> - <% foc += result[:foc_amount].to_f %> - <% card += result[:card_amount].to_f %> - <% total += result[:grand_total].to_f %> - <% rounding_adj += result[:rounding_adj].to_f %> + <% cash += result.cash_sales.to_f %> + <% credit += result.credit_sales.to_f %> + <% card += result.other_sales.to_f %> + + <% total += result.grand_total.to_f %> <% g_total += grand_total.to_f %> <% end %> - - (<%= sprintf("%.2f",void) rescue '-'%>) + + <%= sprintf("%.2f",cash) rescue '-'%> <%= sprintf("%.2f",credit) rescue '-'%> - <%= sprintf("%.2f",accept_credit) rescue '-'%> - <%= sprintf("%.2f",foc) rescue '-'%> + + <%= sprintf("%.2f",card) rescue '-'%> <%= sprintf("%.2f",total) rescue '-'%> - <%= sprintf("%.2f",rounding_adj) rescue '-'%> + <%= sprintf("%.2f",g_total) rescue '-'%> From 155e1a5ba3c9d95901ec448a90e5d63dc3d9a62b Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 30 Jun 2017 14:16:05 +0630 Subject: [PATCH 04/11] hide shiftsale in header --- app/views/layouts/_header.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index ca16298c..558d35dd 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -42,7 +42,7 @@
  • <%= link_to "Daily Sale Report", reports_dailysale_index_path, :tabindex =>"-1" %>
  • <%= link_to "Sales Item Report", reports_saleitem_index_path, :tabindex =>"-1" %>
  • <%= link_to "Receipt Report", reports_receipt_no_index_path, :tabindex =>"-1" %>
  • -
  • <%= link_to "Shift Sale Report", reports_shiftsale_index_path, :tabindex =>"-1" %>
  • + From 45c69ab53605e239ba195e233c772fa407da5bc1 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 30 Jun 2017 15:53:25 +0630 Subject: [PATCH 05/11] update sale ability and shipt slae --- app/models/ability.rb | 5 +++++ app/models/shift_sale.rb | 2 +- app/views/layouts/_header.html.erb | 2 +- app/views/reports/shiftsale/index.html.erb | 8 ++++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 066311af..624fa76a 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -89,6 +89,11 @@ class Ability can :moving, :movetable can :move_dining, :moveroom + + can :first_bill, :payment + can :show, :payment + can :create, :payment + can :reprint, :payment elsif user.role == "accountant" diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index a897de2b..aa4c565f 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -21,7 +21,7 @@ class ShiftSale < ApplicationRecord #find open shift where is open today and is not closed and login by current cashier today_date = DateTime.now.strftime("%Y-%m-%d") puts today_date - shift = ShiftSale.where("TO_CHAR(shift_started_at, 'YYYY-MM-DD')=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}", today_date).take + shift = ShiftSale.where("DATE(shift_started_at)= #{ today_date } and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take return shift #end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 558d35dd..fd951d6c 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -42,7 +42,7 @@
  • <%= link_to "Daily Sale Report", reports_dailysale_index_path, :tabindex =>"-1" %>
  • <%= link_to "Sales Item Report", reports_saleitem_index_path, :tabindex =>"-1" %>
  • <%= link_to "Receipt Report", reports_receipt_no_index_path, :tabindex =>"-1" %>
  • - +
  • <%= link_to "Shift Sale Report", reports_shiftsale_index_path, :tabindex =>"-1" %>
  • diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb index 6a1d69c2..714a8328 100644 --- a/app/views/reports/shiftsale/index.html.erb +++ b/app/views/reports/shiftsale/index.html.erb @@ -42,9 +42,9 @@ Credit Payment - Card Payment - Grand Total + - + Other Payment + Grand Total @@ -101,7 +101,7 @@ <%= sprintf("%.2f",card) rescue '-'%> - <%= sprintf("%.2f",total) rescue '-'%> + <%= sprintf("%.2f",g_total) rescue '-'%> From b0bec2afc4eb98a9c24ff109d6d89575c73311bf Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 30 Jun 2017 16:00:03 +0630 Subject: [PATCH 06/11] add alt name to order and sale items and update seeds --- .../origami/other_charges_controller.rb | 1 + app/models/ability.rb | 7 +++++-- app/models/order.rb | 2 +- app/models/order_item.rb | 3 ++- app/models/sale.rb | 1 + db/migrate/20170403140820_create_order_items.rb | 1 + db/migrate/20170403161857_create_sale_items.rb | 1 + db/seeds.rb | 10 +++++----- lib/tasks/menu_import.rake | 14 +++++++------- 9 files changed, 24 insertions(+), 16 deletions(-) diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index 654f539a..22a4fb2c 100644 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -29,6 +29,7 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.sale_id = sale_id sale_item.product_code = "Other Charges" sale_item.product_name = di["name"] + sale_item.product_alt_name = "" sale_item.remark = "Other Charges" sale_item.qty = 1 diff --git a/app/models/ability.rb b/app/models/ability.rb index 066311af..17c93020 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -40,8 +40,8 @@ class Ability can :add_customer, Customer can :update_sale_by_customer, Customer - can :index, :other_charges - can :create, :other_charges + can :index, :other_charge + can :create, :other_charge can :index, :discount can :create, :discount can :remove_discount_items, :discount @@ -76,11 +76,14 @@ class Ability can :add_customer, Customer can :update_sale_by_customer, Customer + can :index, :other_charge + can :create, :other_charge can :index, :discount can :create, :discount can :remove_discount_items, :discount can :remove_all_discount, :discount + can :first_bill, :payment can :show, :payment can :create, :payment can :reprint, :payment diff --git a/app/models/order.rb b/app/models/order.rb index 249e82ea..714174fe 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -91,7 +91,7 @@ class Order < ApplicationRecord # self.employee_name) # end - OrderItem.processs_item(menu_item[:item_code], menu_item[:name], menu_item[:account_id], + OrderItem.processs_item(menu_item[:item_code], menu_item[:name], menu_item[:alt_name], menu_item[:account_id], item[:quantity],menu_item[:price], item[:options], set_order_items, self.id, self.employee_name) diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 2c9a9ba0..f4f3efba 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -20,12 +20,13 @@ class OrderItem < ApplicationRecord # option_values : [], # sub_order_items : [], # } - def self.processs_item (item_code, menu_name, account_id, qty,price, options, set_menu_items, order_id, item_order_by) + def self.processs_item (item_code, menu_name, alt_name, account_id, qty,price, options, set_menu_items, order_id, item_order_by) orderitem = OrderItem.create do |oitem| oitem.order_id = order_id oitem.item_code = item_code oitem.item_name = menu_name + oitem.alt_name = alt_name oitem.account_id = account_id oitem.qty = qty oitem.price = price diff --git a/app/models/sale.rb b/app/models/sale.rb index 693f6874..a05455c2 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -148,6 +148,7 @@ class Sale < ApplicationRecord #pull sale_item.product_code = item.item_code sale_item.product_name = item.item_name + sale_item.product_alt_name = item.alt_name sale_item.account_id = item.account_id sale_item.remark = item.remark diff --git a/db/migrate/20170403140820_create_order_items.rb b/db/migrate/20170403140820_create_order_items.rb index ca1166dc..1882bd62 100644 --- a/db/migrate/20170403140820_create_order_items.rb +++ b/db/migrate/20170403140820_create_order_items.rb @@ -7,6 +7,7 @@ class CreateOrderItems < ActiveRecord::Migration[5.1] t.string :item_order_by #person who order this t.string :item_code, :null => false t.string :item_name, :null => false + t.string :alt_name, :null => false t.integer :account_id, :limit => 8, :null => false, :default => 1 t.decimal :qty, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :price, :precision => 10, :scale => 2, :null => false, :default => 0.00 diff --git a/db/migrate/20170403161857_create_sale_items.rb b/db/migrate/20170403161857_create_sale_items.rb index 48b1363e..d42b6f3c 100644 --- a/db/migrate/20170403161857_create_sale_items.rb +++ b/db/migrate/20170403161857_create_sale_items.rb @@ -5,6 +5,7 @@ class CreateSaleItems < ActiveRecord::Migration[5.1] t.string :sale_id, foreign_key: true, :limit => 16 t.string :product_code, :null => false t.string :product_name, :null => false + t.string :product_alt_name, :null => false t.integer :account_id, :limit => 8, :null => false, :default => 1 t.string :remark t.decimal :qty, :precision => 10, :scale => 2, :null => false, :default => 0.00 diff --git a/db/seeds.rb b/db/seeds.rb index 2635ab4f..b71418a9 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -156,11 +156,11 @@ admin_employee = Employee.create({name: "Waiter", role: "waiter", password: "111 admin_employee = Employee.create({name: "Waiter 2", role: "waiter", password: "22222", emp_id:"222", created_by: "SYSTEM DEFAULT"}) admin_employee = Employee.create({name: "Cashier", role: "cashier", password: "33333", emp_id:"333", created_by: "SYSTEM DEFAULT"}) -order_station1=PrintSetting.create({name: "OrderItemPdf", unique_code: "OrderItemPdf", printer_name: "EPSON-TM-T82-S-A", precision: "0", delimiter: "0", heading_space: "5"}) -order_station2=PrintSetting.create({name: "Order Summary", unique_code: "OrderSummaryPdf", printer_name: "EPSON-TM-T82-S-A", precision: "0", delimiter: "0", heading_space: "5"}) -request_bill_printer=PrintSetting.create({name: "Receipt Bill", unique_code: "ReceiptBillPdf", printer_name: "EPSON-TM-T82-S-A", precision: "0", delimiter: "0", heading_space: "5"}) -crm_order_printer=PrintSetting.create({name: "CRM Order", unique_code: "CrmOrderPdf", printer_name: "EPSON-TM-T82-S-A", precision: "0", delimiter: "0", heading_space: "5"}) -queue_no_printer=PrintSetting.create({name: "Queue No", unique_code: "QueueNoPdf", printer_name: "EPSON-TM-T82-S-A", precision: "0", delimiter: "0", heading_space: "5"}) +order_station1=PrintSetting.create({name: "OrderItemPdf", unique_code: "OrderItemPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) +order_station2=PrintSetting.create({name: "Order Summary", unique_code: "OrderSummaryPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) +request_bill_printer=PrintSetting.create({name: "Receipt Bill", unique_code: "ReceiptBillPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) +crm_order_printer=PrintSetting.create({name: "CRM Order", unique_code: "CrmOrderPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) +queue_no_printer=PrintSetting.create({name: "Queue No", unique_code: "QueueNoPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) member_setting = MembershipSetting.create({membership_type:"paypar_url",gateway_url: "http://192.168.1.47:3006",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}) diff --git a/lib/tasks/menu_import.rake b/lib/tasks/menu_import.rake index 1979d364..e06390d4 100644 --- a/lib/tasks/menu_import.rake +++ b/lib/tasks/menu_import.rake @@ -9,7 +9,7 @@ beverage = Account.create({title: "Beverage", account_type: "1"}) menu_category1 = MenuCategory.create({menu: menu, code:"C001", name: "Soup Base", alt_name: "Soup_base", order_by: 1,created_by: "SYSTEM DEFAULT"}) # single pot menu_category1_menu_item0 = SimpleMenuItem.create({item_code:"01001", name: "Single Pot", alt_name: "Single Pot",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1, account: food }) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Single Pot",item_instance_code:"II0011", menu_item: menu_category1_menu_item0, price:10.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Single Pot",item_instance_code:"II0011", menu_item: menu_category1_menu_item0, price:0.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Beauty Collagen Broth",item_instance_code:"II0051", menu_item: menu_category1_menu_item0, price:15800.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Spicy Nourishing Broth ",item_instance_code:"II0061", menu_item: menu_category1_menu_item0, price:15800.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Herbal Drunken Chicken Broth",item_instance_code:"II0071", menu_item: menu_category1_menu_item0, price:17800.00, is_on_promotion:false}]) @@ -18,7 +18,7 @@ menu_category1 = MenuCategory.create({menu: menu, code:"C001", name: "Soup Base" menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Vitamin C Tomato Sweet Corn Broth",item_instance_code:"II0101", menu_item: menu_category1_menu_item0, price:15800.00, is_on_promotion:false}]) # twin pot menu_category1_menu_item1 = SimpleMenuItem.create({item_code:"01002", name: "Twin Pot", alt_name: "Twin Pot",menu_category: menu_category1 , min_selectable_item: 2, max_selectable_item:2, account: food }) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Twin Pot",item_instance_code:"II0021", menu_item: menu_category1_menu_item1, price:10.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Twin Pot",item_instance_code:"II0021", menu_item: menu_category1_menu_item1, price:0.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Beauty Collagen Broth",item_instance_code:"II0052", menu_item: menu_category1_menu_item1, price:9800.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Spicy Nourishing Broth ",item_instance_code:"II0062", menu_item: menu_category1_menu_item1, price:9800.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Herbal Drunken Chicken Broth",item_instance_code:"II0072", menu_item: menu_category1_menu_item1, price:9800.00, is_on_promotion:false}]) @@ -27,7 +27,7 @@ menu_category1 = MenuCategory.create({menu: menu, code:"C001", name: "Soup Base" menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Vitamin C Tomato Sweet Corn Broth",item_instance_code:"II0102", menu_item: menu_category1_menu_item1, price:11800.00, is_on_promotion:false}]) # vip room Individual pot menu_category1_menu_item2 = SimpleMenuItem.create({item_code:"01003", name: "VIP Room Individual Pot", alt_name: "Single Pot",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1, account: food }) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"VIP Room Individual Pot",item_instance_code:"II0031", menu_item: menu_category1_menu_item2, price:10.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"VIP Room Individual Pot",item_instance_code:"II0031", menu_item: menu_category1_menu_item2, price:0.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Beauty Collagen Broth",item_instance_code:"II0053", menu_item: menu_category1_menu_item2, price:6000.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Spicy Nourishing Broth ",item_instance_code:"II0063", menu_item: menu_category1_menu_item2, price:6000.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Herbal Drunken Chicken Broth",item_instance_code:"II0073", menu_item: menu_category1_menu_item2, price:8000.00, is_on_promotion:false}]) @@ -36,7 +36,7 @@ menu_category1 = MenuCategory.create({menu: menu, code:"C001", name: "Soup Base" menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Vitamin C Tomato Sweet Corn Broth",item_instance_code:"II0103", menu_item: menu_category1_menu_item2, price:6000.00, is_on_promotion:false}]) # Quart pot menu_category1_menu_item3 = SimpleMenuItem.create({item_code:"01004", name: "Quart Pot", alt_name: "Quart Pot",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1, account: food }) - menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Quart Pot",item_instance_code:"II0041", menu_item: menu_category1_menu_item3, price:10.00, is_on_promotion:false}]) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Quart Pot",item_instance_code:"II0041", menu_item: menu_category1_menu_item3, price:0.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Beauty Collagen Broth",item_instance_code:"II0054", menu_item: menu_category1_menu_item3, price:6000.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Spicy Nourishing Broth ",item_instance_code:"II0064", menu_item: menu_category1_menu_item3, price:6000.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Herbal Drunken Chicken Broth",item_instance_code:"II0074", menu_item: menu_category1_menu_item3, price:8000.00, is_on_promotion:false}]) @@ -626,9 +626,9 @@ zone3 = Zone.create({id:3, name: "H3", is_active:true, created_by: "SYSTEM DEFAU table = Table.create({name:"78", zone: zone3, status:"available", seater: 2 , order_by:1, created_by:"SYSTEM DEFAULT"}) #Default Order Queue stations -order_queue_station1 = OrderQueueStation.create({station_name: "K1", is_active: true,printer_name: "kitchen_printer", processing_items: JSON.generate(['01001','01002','01003','01004']), print_copy:true, cut_per_item: false, use_alternate_name: false, created_by: "SYSTEM DEFAULT"}) -order_queue_station2 = OrderQueueStation.create({station_name: "K2", is_active: true,printer_name: "drink_printer", processing_items: JSON.generate(['02005','02006','02007','02008']), print_copy:true, cut_per_item: true, use_alternate_name: true, created_by: "SYSTEM DEFAULT"}) -zone_order_queue_station = OrderQueueStation.create({station_name: "K3", is_active: true, printer_name: "print_station", processing_items: JSON.generate(['01001','01002','01003','01004','02005','02006','02007','02008']), print_copy: true, cut_per_item: true, use_alternate_name: false, created_by: "SYSTEM DEFAULT"}) +order_queue_station1 = OrderQueueStation.create({station_name: "K1", is_active: true,printer_name: "Cashier", processing_items: JSON.generate(['01001','01002','01003','01004']), print_copy:true, cut_per_item: false, use_alternate_name: false, created_by: "SYSTEM DEFAULT"}) +order_queue_station2 = OrderQueueStation.create({station_name: "K2", is_active: true,printer_name: "Cashier", processing_items: JSON.generate(['02005','02006','02007','02008']), print_copy:true, cut_per_item: true, use_alternate_name: true, created_by: "SYSTEM DEFAULT"}) +zone_order_queue_station = OrderQueueStation.create({station_name: "K3", is_active: true, printer_name: "Cashier", processing_items: JSON.generate(['01001','01002','01003','01004','02005','02006','02007','02008']), print_copy: true, cut_per_item: true, use_alternate_name: false, created_by: "SYSTEM DEFAULT"}) # QueueStationZone zone_queue_station1 = OrderQueueProcessByZone.create({order_queue_station: order_queue_station1, zone: zone}) From 2548fdcac1c040183a61dfeb92faed082c73f87d Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 30 Jun 2017 18:02:17 +0630 Subject: [PATCH 07/11] update receipt bill --- .../origami/payments_controller.rb | 11 +- .../reports/shiftsale_controller.rb | 2 +- app/models/ability.rb | 11 +- app/models/sale.rb | 1 - app/pdf/receipt_bill_pdf.rb | 33 ++- app/views/crm/customers/show.html.erb | 2 +- app/views/reports/shiftsale/index.xls.erb | 194 ++++++++---------- 7 files changed, 121 insertions(+), 133 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 0d2d9082..2cdd44b5 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -9,10 +9,6 @@ class Origami::PaymentsController < BaseOrigamiController sale_data = Sale.find_by_sale_id(sale_id) sale_items = SaleItem.where("sale_id=?",sale_id) - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - rounding_adj = sale_data.grand_total - new_total - - sale_data.update_attributes(grand_total: new_total,rounding_adjustment:rounding_adj) # Print for First Bill to Customer unique_code = "ReceiptBillPdf" @@ -43,7 +39,12 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - sale_payment.process_payment(saleObj, @user, cash, "cash") + sale_payment.process_payment(saleObj, @user, cash, "cash") + + new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + rounding_adj = saleObj.grand_total - new_total + + saleObj.update_attributes(grand_total: new_total,rounding_adjustment:rounding_adj) rebate_amount = nil diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb index 6d8df8c6..87fae97d 100644 --- a/app/controllers/reports/shiftsale_controller.rb +++ b/app/controllers/reports/shiftsale_controller.rb @@ -1,5 +1,5 @@ class Reports::ShiftsaleController < BaseReportController - # authorize_resource :class => false + authorize_resource :class => false def index diff --git a/app/models/ability.rb b/app/models/ability.rb index 624fa76a..c4120bc1 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -36,6 +36,7 @@ class Ability can :index, :dailysale can :index, :saleitem can :index, :receipt_no + can :index, :shiftsale can :add_customer, Customer can :update_sale_by_customer, Customer @@ -98,14 +99,16 @@ class Ability elsif user.role == "accountant" can :index, :dailysale - can :manage, :saleitem - can :index, :receiptno + can :index, :saleitem + can :index, :receipt_no + can :index, :shiftsale elsif user.role == "supervisour" can :index, :dailysale - can :manage, :saleitem - can :index, :receiptno + can :index, :saleitem + can :index, :receipt_no + can :index, :shiftsale end diff --git a/app/models/sale.rb b/app/models/sale.rb index deb9be9e..2e8794d5 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -93,7 +93,6 @@ class Sale < ApplicationRecord end - self.save! #compute sales summary diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 3817c509..bff0852d 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -95,7 +95,7 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do - text "Receipt Date : #{ sale_data.receipt_date.strftime('%d-%m-%Y') } ( #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } - #{ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p') } )",:size => self.item_font_size,:align => :left + text "Date : #{ sale_data.receipt_date.strftime('%d-%m-%Y') } ( #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } - #{ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p') } )",:size => self.item_font_size,:align => :left end @@ -202,6 +202,18 @@ class ReceiptBillPdf < Prawn::Document # text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right # end + if sale_data.rounding_adjustment != 0.0 + move_down 5 + y_position = cursor + + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Rounding Adjustment", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right + end + end + move_down 5 y_position = cursor move_down 5 @@ -253,18 +265,13 @@ class ReceiptBillPdf < Prawn::Document if rebate_amount["status"] == true stroke_horizontal_rule + rebate = 0 rebate_amount["data"].each do |res| if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Rebate" - move_down 5 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Current Rebate Amount", :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(res["rebate"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end + rebate = rebate + res["rebate"] + end if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Redeem" @@ -279,6 +286,14 @@ class ReceiptBillPdf < Prawn::Document end end + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Current Rebate Amount", :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(rebate, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end end end if member_info["status"] == true && member_info["data"].present? diff --git a/app/views/crm/customers/show.html.erb b/app/views/crm/customers/show.html.erb index 3cf08856..5d36f5c3 100644 --- a/app/views/crm/customers/show.html.erb +++ b/app/views/crm/customers/show.html.erb @@ -60,7 +60,7 @@ Membership Transactions <% if @response["status"] == true %> - Current Balance : <%= @response["data"][0]["balance"]%> + Current Balance : <%= @response["data"].last["balance"]%> <% end %> <% end %> diff --git a/app/views/reports/shiftsale/index.xls.erb b/app/views/reports/shiftsale/index.xls.erb index 67e76e3c..c2a8a6d2 100644 --- a/app/views/reports/shiftsale/index.xls.erb +++ b/app/views/reports/shiftsale/index.xls.erb @@ -1,116 +1,86 @@ -
    -
    - - - <% if params[:from]%> - - - - <% end %> - - - - - - - - - - - - - - - - - - - <% unless @sale_data.empty? %> - - - <% void = 0 %> - <% mpu = 0 %> - <% master = 0 %> - <% visa = 0 %> - <% jcb = 0 %> - <% paypar = 0 %> - <% cash = 0 %> - <% credit = 0 %> - <% foc = 0 %> - <% discount = 0 %> - <% total = 0 %> - <% grand_total = 0 %> - <% count = 1 %> <% rounding_adj = 0 %> - <% @sale_data.each do |sale| %> - <% void += sale[:void_amount] %> - <% mpu += sale[:mpu_amount] %> - <% master += sale[:master_amount] %> - <% visa += sale[:visa_amount] %> - <% jcb += sale[:jcb_amount] %> - <% paypar += sale[:paypar_amount] %> - <% cash += sale[:cash_amount] %> - <% credit += sale[:credit_amount] %> - <% foc += sale[:foc_amount] %> - <% discount += sale[:total_discount] %> - <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> - <% grand_total += sale[:grand_total].to_f %> - <% rounding_adj += sale[:rounding_adj].to_f %> - - - - - - - - - - - - - - - - - - <% count = count + 1 %> - <% end %> +
    +
    +
    Sale (<%= params[:from] rescue '-' %> - <%= params[:to] rescue '-'%>)
    Sr.noDateVoid AmountMpu SalesMaster SalesVisa SalesJcb SalesPaypar SalesCash SalesCredit SalesFOC Sales(Discount)Grand Total +
    Rounding Adj.
    Rounding Adj.Grand Total
    <%= count %><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %><%= number_with_delimiter(sprintf("%.2f",sale[:void_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:mpu_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:master_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:visa_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:jcb_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:paypar_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]), :delimiter => ',') rescue '-'%>(<%= number_with_delimiter(sprintf("%.2f",sale[:total_discount]), :delimiter => ',') rescue '-'%>)<%= number_with_delimiter(sprintf("%.2f",sale[:grand_total].to_f + sale[:rounding_adj].to_f ), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:rounding_adj].to_f), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",sale[:grand_total]), :delimiter => ',') rescue '-'%>
    + + <% if params[:from]%> + + + + <% end %> + + + + + + + + + + + + + + + + + + <% void = 0%> + <% cash = 0%> + <% credit = 0%> + <% accept_credit = 0%> + <% foc = 0%> + <% card = 0%> + <% total = 0%> + <% rounding_adj = 0%> + <% g_total = 0 %> - - - - - - - - - - - - - - - + <% @sale_data.each do |result|%> + + + + + + + + + + + - <% total_tax = 0 %> - <% unless @tax.empty? %> - <% @tax.each do |tax| %> - <% total_tax += tax.tax_amount.to_f %> - - - - - - - <% end %> - <% net = total - total_tax %> - - - - - - <% end %> - - <% end %> -
    From Date : <%= params[:from] rescue '-'%> ,To Date : <%= params[:to] rescue '-'%>
    Cashier StationCashier NameShift NameCash PaymentCredit PaymentOther PaymentGrand Total
    Total<%= number_with_delimiter(sprintf("%.2f",mpu_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",master_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",visa_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",jcb_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",paypar_amount), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",cash), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",credit), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",foc), :delimiter => ',') rescue '-'%>(<%= number_with_delimiter(sprintf("%.2f",discount), :delimiter => ',') rescue '-'%>)<%= number_with_delimiter(sprintf("%.2f",total), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",rounding_adj), :delimiter => ',') rescue '-'%><%= number_with_delimiter(sprintf("%.2f",grand_total), :delimiter => ',') rescue '-'%>
    + <%= result.cashier_terminal.name rescue '-'%> + + <%= result.employee.name rescue '-'%> + <%= result.shift_started_at.strftime("%e %b %I:%M%p") rescue '-' %> - + <%= result.shift_closed_at.strftime("%e %b %I:%M%p") rescue '-' %> + <%= sprintf "%.2f",result.cash_sales.to_f.to_d rescue '-'%><%= sprintf "%.2f",result.credit_sales.to_f.to_d rescue '-'%><%= sprintf "%.2f",result.other_sales.to_f.to_d rescue '-'%><%= sprintf "%.2f",result.grand_total.to_f.to_d rescue '-'%>
    <%= tax.tax_name rescue '-'%><%= number_with_delimiter(sprintf("%.2f",tax.tax_amount), :delimiter => ',') rescue '-'%> 
    Net Amount<%= number_with_delimiter(sprintf("%.2f",net), :delimiter => ',') rescue '-'%> 
    + + <% grand_total = result.grand_total.to_f %> + <%= sprintf "%.2f",grand_tota.to_f.to_d rescue '-'%> + + <% cash += result.cash_sales.to_f %> + <% credit += result.credit_sales.to_f %> + <% card += result.other_sales.to_f %> + + <% total += result.grand_total.to_f %> + <% g_total += grand_total.to_f %> + + <% end %> + + + + + <%= sprintf("%.2f",cash) rescue '-'%> + <%= sprintf("%.2f",credit) rescue '-'%> + + + <%= sprintf("%.2f",card) rescue '-'%> + + + <%= sprintf("%.2f",g_total) rescue '-'%> + + +
    \ No newline at end of file From 71636b36db6bb444f230635851f63155d5633f07 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 30 Jun 2017 19:05:13 +0630 Subject: [PATCH 08/11] add Re-compute all amoute for sale --- .../origami/discounts_controller.rb | 14 +++-- .../origami/other_charges_controller.rb | 18 +++--- app/controllers/origami/sales_controller.rb | 3 + app/models/sale.rb | 62 +++++++++++++++++++ app/models/sale_payment.rb | 8 +++ 5 files changed, 93 insertions(+), 12 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 6c76c27a..02a85f91 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -22,10 +22,10 @@ class Origami::DiscountsController < BaseOrigamiController sale = Sale.find(sale_id) table_id = sale.bookings[0].dining_facility_id table_type = DiningFacility.find(table_id).type - sale.total_discount = overall_discount.to_f - sale.total_amount = sub_total.to_f - sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax; - sale.save + # sale.total_discount = overall_discount.to_f + # sale.total_amount = sub_total.to_f + # sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax; + # sale.save if discount_items.length > 0 #save sale item for discount discount_items.each do |di| @@ -35,6 +35,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.sale_id = sale_id sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id sale_item.product_name = di["name"] + sale_item.product_alt_name = "" sale_item.remark = "Discount" sale_item.qty = 1 @@ -45,7 +46,10 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.price = di["price"] sale_item.save end - end + end + + # Re-calc All Amount in Sale + sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) end dining = {:table_id => table_id, :table_type => table_type } diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index 22a4fb2c..a23ebd16 100644 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -16,10 +16,11 @@ class Origami::OtherChargesController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find(sale_id) table_id = sale.bookings[0].dining_facility_id - table_type = DiningFacility.find(table_id).type - sale.total_amount = sub_total.to_f - sale.grand_total = sub_total.to_f + sale.total_tax; - sale.save + table_type = DiningFacility.find(table_id).type + + # sale.total_amount = sub_total.to_f + # sale.grand_total = sub_total.to_f + sale.total_tax; + # sale.save if other_charges_items.length > 0 #save sale item for discount other_charges_items.each do |di| @@ -34,14 +35,17 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.qty = 1 sale_item.unit_price = di["price"] - sale_item.taxable_price = di["price"] + sale_item.taxable_price = 0 sale_item.is_taxable = 0 sale_item.price = di["price"] sale_item.save end - end - end + end + + # Re-calc All Amount in Sale + sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount) + end dining = {:table_id => table_id, :table_type => table_type } render :json => dining.to_json diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index e272c1ee..c397da0f 100644 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -26,6 +26,9 @@ class Origami::SalesController < BaseOrigamiController order.order_items.each do |orer_item| saleobj.add_item (orer_item) end + + # Re-compute for add + saleobj.compute saleobj.save order.save booking.save diff --git a/app/models/sale.rb b/app/models/sale.rb index 6ab83279..0df2d81b 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -41,8 +41,10 @@ class Sale < ApplicationRecord end booking.sale_id = sale_id end + order = booking.booking_orders.take.order link_order_sale(order.id) + return status, sale_id end end @@ -207,6 +209,33 @@ class Sale < ApplicationRecord end + #compute - invoice total + def compute_by_sale_items(sale_id, sale_itemss, total_discount) + sale = Sale.find(sale_id) + sales_items = sale_itemss + + #Computation Fields + subtotal_price = 0 + total_taxable = 0 + rounding_adjustment = 0 + + sales_items.each do |item| + #compute each item and added to total + subtotal_price = subtotal_price + item.price + total_taxable = total_taxable + (item.taxable_price * item.qty) + end + + compute_tax(sale, total_taxable) + sale.total_amount = subtotal_price + sale.total_discount = total_discount + sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax + #compute rounding adjustment + # adjust_rounding + + sale.save! + + end + def compute_without_void sales_items = self.sale_items @@ -232,6 +261,39 @@ class Sale < ApplicationRecord self.save! end + + # Tax Re-Calculte + def compute_tax(sale, total_taxable) + #if tax is not apply create new record + SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax| + #delete existing and create new + existing_tax.delete + end + + total_tax_amount = 0 + #tax_profile - list by order_by + tax_profiles = TaxProfile.all.order("order_by asc") + + # #Creat new tax records + tax_profiles.each do |tax| + sale_tax = SaleTax.new(:sale => sale) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate + #include or execulive + # sale_tax.tax_payable_amount = total_taxable * tax.rate + sale_tax.tax_payable_amount = total_taxable * tax.rate / 100 + #new taxable amount + total_taxable = total_taxable + sale_tax.tax_payable_amount + + sale_tax.inclusive = tax.inclusive + sale_tax.save + + total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount + end + + sale.total_tax = total_tax_amount + end + # Tax Calculate def apply_tax(total_taxable) #if tax is not apply create new record diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index c78b6cd8..11b201d2 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -54,6 +54,14 @@ class SalePayment < ApplicationRecord remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by) + # update complete order items in oqs + SaleOrder.where("sale_id = '#{ invoice.sale_id }'").find_each do |sodr| + AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| + aoi.delivery_status = 1 + aoi.save + end + end + return true, self.save else #record an payment in sale-audit From a851f6de70ffb26221a7c5ac3b2320cdd1752d57 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 30 Jun 2017 19:27:46 +0630 Subject: [PATCH 09/11] update taxobj in sale --- app/models/sale.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 5a8f5359..55e53d39 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -598,9 +598,9 @@ end def get_commerical_tax tax = 0.0 - self.sale_taxes.each do |tax| - if tax.tax_name == "Commerical Tax" - tax += tax.tax_payable_amount + self.sale_taxes.each do |taxobj| + if taxobj.tax_name == "Commerical Tax" + tax += taxobj.tax_payable_amount end end end From 3681a9558bdd83ce0ed53059b4f9321000163a51 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 30 Jun 2017 19:35:00 +0630 Subject: [PATCH 10/11] sale return --- app/models/sale.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/sale.rb b/app/models/sale.rb index 55e53d39..2578221d 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -603,6 +603,7 @@ end tax += taxobj.tax_payable_amount end end + return tax end private From 219944abbdc533708eedaf3d01c08e7d610bad0c Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 30 Jun 2017 20:07:49 +0630 Subject: [PATCH 11/11] update migrate --- db/migrate/20170403160742_create_sales.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20170403160742_create_sales.rb b/db/migrate/20170403160742_create_sales.rb index ae806472..9deeb9b8 100644 --- a/db/migrate/20170403160742_create_sales.rb +++ b/db/migrate/20170403160742_create_sales.rb @@ -20,7 +20,7 @@ class CreateSales < ActiveRecord::Migration[5.1] t.decimal :rounding_adjustment, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :amount_received, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :amount_changed, :precision => 10, :scale => 2, :null => false, :default => 0.00 - t.integer :shift_sale_id, :null => false + t.integer :shift_sale_id t.timestamps end end