diff --git a/README.md b/README.md index 9df29b68..4d81b144 100755 --- a/README.md +++ b/README.md @@ -93,6 +93,12 @@ For Show Sale Items Summary at CloseCashierPrint 1) settings/print_settings a) Check => Shift Sale Items +For Show/Hide AddOrder Button in QuickService + 1) settings/lookups => {type:quickservice_add_order, name: QuickServiceAddOrder, value:1 OR 0} + +For Show Print Button in ReceiptNo Report + 1) settings/lookups => {type:reprint_receipt, name: Reprint Receipt in Report, value:1} + For Bank Integration setting 1) rake db:migrate for card_sale_trans, card_settle_trans 2) settings/lookups => { type:bank_integration, name: Bank Integration, value:1 } diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index 8fb6895c..cc39db10 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -30,7 +30,7 @@ class Origami::QuickServiceController < ApplicationController end #checked quick_service only - @quick_service_only = false + @quick_service_only = false lookup_dine_in = Lookup.collection_of('quickservice_add_order') puts 'lookup_dine_in!!!!' puts lookup_dine_in diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index b05db409..eeff4bf0 100755 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -1,4 +1,4 @@ -class Reports::ReceiptNoController < BaseReportController +class Reports::ReceiptNoController < BaseReportController authorize_resource :class => false def index @payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"]] @@ -13,7 +13,7 @@ authorize_resource :class => false @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale = ShiftSale.find(params[:shift_name]) - if to.blank? + if to.blank? @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) else if @shift_sale.shift_closed_at.blank? @@ -24,8 +24,13 @@ authorize_resource :class => false end end + @lookup = Lookup.find_by_lookup_type('reprint_receipt') + if @lookup.nil? + @lookup = Lookup.create_reprint_receipt_lookup + end + payment_type = params[:payment_type] - @sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to,payment_type) + @sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to,payment_type) @sale_taxes = Sale.get_separate_tax(@shift_sale_range,@shift,from,to,payment_type) @tax_profiles = TaxProfile.group('name').order('order_by asc') #.limit(2) @@ -64,7 +69,7 @@ authorize_resource :class => false end out = {:status => 'ok', :message => date_arr} - + respond_to do |format| format.json { render json: out } end @@ -126,5 +131,109 @@ authorize_resource :class => false format.html { redirect_to '/en/reports/receipt_no/', notice: @message} end end - -end \ No newline at end of file + + def reprint + sale_id = params[:sale_id] + member_info = nil + latest_order_no = nil + saleObj = Sale.find(sale_id) + + # For Cashier by Zone + bookings = Booking.where("sale_id='#{sale_id}'") + + booking = Booking.find_by_sale_id(sale_id) + latest_order = booking.booking_orders.joins(" JOIN orders ON orders.order_id = booking_orders.order_id").where("orders.source = 'quick_service'").order("order_id DESC").limit(1).first() + if !latest_order.nil? + latest_order_no = latest_order.order_id + end + # if bookings.count > 1 + # # for Multiple Booking + # table = DiningFacility.find(bookings[0].dining_facility_id) + # else + # table = DiningFacility.find(bookings[0].dining_facility_id) + # end + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + else + if bookings[0].dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end + end + + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + unique_code = "ReceiptBillPdf" + if !receipt_bill_a5_pdf.empty? + receipt_bill_a5_pdf.each do |receipt_bilA5| + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[1] == '1' + unique_code = "ReceiptBillA5Pdf" + else + unique_code = "ReceiptBillPdf" + end + end + end + end + customer= Customer.find(saleObj.customer_id) + + #shop detail + #shop_detail = Shop.first + # get member information + rebate = MembershipSetting.find_by_rebate(1) + if customer.membership_id != nil && rebate + member_info = Customer.get_member_account(customer) + rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) + current_balance = SaleAudit.paymal_search(sale_id) + end + + #for card sale data + card_data = Array.new + card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id) + if !card_sale_trans_ref_no.nil? + card_sale_trans_ref_no.each do |cash_sale_trans| + card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s + card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s + card_no = cash_sale_trans.pan.last(4) + card_no = card_no.rjust(19,"**** **** **** ") + card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id}) + end + end + + #card_balance amount for Paymal payment + card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id) + + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_code) + + # Calculate price_by_accounts + item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) + other_amount = SaleItem.calculate_other_charges(saleObj.sale_items) + + printer = Printer::ReceiptPrinter.new(print_settings) + + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) + + result = { + :status => true, + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + # render :json => result.to_json + respond_to do |format| + format.html { redirect_to '/en/reports/receipt_no/', notice: "Printing Completed."} + format.json { render json: result } + end + # end + end + +end diff --git a/app/models/lookup.rb b/app/models/lookup.rb index 2120cfe6..b446d4e8 100755 --- a/app/models/lookup.rb +++ b/app/models/lookup.rb @@ -1,5 +1,5 @@ class Lookup < ApplicationRecord - + has_many :accounts def available_types @@ -18,7 +18,7 @@ class Lookup < ApplicationRecord end # def self.get_by_type( lookup_type) - # Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] } + # Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] } # end def self.get_checkin_time_limit @@ -69,6 +69,16 @@ class Lookup < ApplicationRecord return @lookup end + def self.create_reprint_receipt_lookup + @lookup = Lookup.new + @lookup.lookup_type = 'reprint_receipt' + @lookup.name = 'Reprint Receipt in Report' + @lookup.value = 0 + @lookup.save + + return @lookup + end + def self.save_shift_sale_items_settings(val) @lookup = Lookup.where('lookup_type=?', 'shift_sale_items').last if @lookup.nil? diff --git a/app/models/sale.rb b/app/models/sale.rb index 55fcd9ad..67245590 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -241,9 +241,9 @@ class Sale < ApplicationRecord # @sale_data.save # Promotion Activation - Promotion.promo_activate(@sale) + Promotion.promo_activate(@sale_data) @status = true - return @status, @sale + return @status, @sale_data else @status = false @message = "No Current Open Shift for This Employee" diff --git a/app/views/reports/receipt_no/index.html.erb b/app/views/reports/receipt_no/index.html.erb index 5bfdeba8..fbd49e3e 100755 --- a/app/views/reports/receipt_no/index.html.erb +++ b/app/views/reports/receipt_no/index.html.erb @@ -56,7 +56,7 @@